1.Write up the linked list code in a form to be run by a user. 2.Create three di
ID: 3599561 • Letter: 1
Question
1.Write up the linked list code in a form to be run by a user.
2.Create three different types of lists, each in its own class.
a.Type 1 is a singly-linked list, no tail reference, non-circular, containing Integers.
b.Type 2 is a doubly-linked list with a tail reference, non-circular, containing Doubles.
c.Type 3 is a singly-linked circular list, your choice of a tail reference or not, (whichever will favor the operations) containing Strings.
3.The driver class (containing the main method) will handle user input. It will have three variables (objects), one for each list type.
4.Input will be from a user. You may assume a perfect user ( don’t handle any errors). They will make menu choices (ints) and enter list data.
5.The program will allow a user to, first, choose which of the three types of list to use, then, second, what operation they wish to run on one of those lists. Use simple text output for displaying the menus and getting user input. Sample menus
(top-level menu)
Pick a list type:
singly-linked, no tail reference, non-circular, Integers
doubly-linked, tail reference, non-circular, Doubles
singly-linked, circular (add tail or not, depending on what you implement), Strings
or 4. exit the program
---
(list-specific menus)
Type 1 operations
build a list
clear the list
check if the list is sorted
insert at head
insert at tail
Explanation / Answer
package com;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.util.ArrayList;
import java.util.Random;
import javax.swing.JPanel;
public class Graph extends JPanel {
public Graph() {
setSize(500, 500);
}
@Override
public void paintComponent(Graphics g) {
Graphics2D gr = (Graphics2D) g; // This is if you want to use Graphics2D
// Now do the drawing here
ArrayList<Integer> scores = new ArrayList<Integer>(10);
Random r = new Random();
for (int i : scores) {
i = r.nextInt(20);
System.out.println(r);
}
int y1;
int y2;
for (int i = 0; i < scores.size() - 1; i++) {
y1 = (scores.get(i)) * 10;
y2 = (scores.get(i + 1)) * 10;
gr.drawLine(i * 10, y1, (i + 1) * 10, y2);
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.