Description:
The main objective of this lab was to use data structure to implements different ways we will display number as it was entered. Such as in reversed order, the order that they were entered, or even the ascending order of the numbers that was entering from lowest to largest. In addition to showing the number in its ascending order we were also require to show the number for duplicate numbers only once. So for example if I enter two six, the Treeset method will only show the number six once in it output not twice and when we run it we can see how the display a good rule in this code.
CODE
import java.util.*;
public class DataStructure {
private static Scanner scanner;
public static void main(String[] args) {
scanner = new Scanner(System.in);
Double Number;
ArrayList
Stack
Queue
TreeSet
do {
System.out.println(“Please enter as many numbers as you like,to exit enter a non number letter on your keyboard:”);
Number = scanner.nextDouble();
list.add(Number);
stack.push(Number);
queue.offer(Number);
setList.add(Number);
} while (scanner.hasNextDouble());
if (!scanner.hasNextDouble()) {
System.out.println(“\n numbers in the order entered are as follow: “);
for (int i = 0; i < list.size(); i++) {
System.out.print(list.get(i) + " ");
}
System.out.println("\n\n The numbers in reverse order as entered as follow: ");
while (!stack.empty()) {
System.out.print(stack.peek() + " ");
stack.pop();
}
System.out.println("\n\nThe numbers in ascending order is as follow: ");
while (queue.size() > 0) {
System.out.print(queue.peek() + ” “);
queue.poll();
}
System.out.println(“\n\nThe numbers in ascending order with no duplicates is as follow: “);
while (!setList.isEmpty()) {
System.out.print(setList.first() + ” “);
setList.remove(setList.first());
}
}
}
}