Description:
For our Eighth Lab, we had to create a program to organize data.
Code:
package dataStructures; import java.util.Collections; import java.util.LinkedList; import java.util.Scanner; import java.util.Stack; import java.util.TreeSet; public class DataStructures { public static void main(String[] args) { Scanner input = new Scanner(System.in); int choice = 0; System.out.println("Enter the number of the data type you want to use: "); System.out.println("1 - Integer "); System.out.println("2 - Double "); System.out.println("3 - String "); choice = input.nextInt(); System.out.printf("You have selected: %d\n",choice); if (choice == 1) { Stacks = new Stack (); LinkedList a = new LinkedList (); LinkedList b = new LinkedList (); TreeSet t = new TreeSet (); int x = 0; int y = 0; System.out.println("Enter how many numbers you want: "); x = input.nextInt(); System.out.println("Enter the numbers you want: "); while (y < x) { Integer Number = input.nextInt(); a.addFirst(Number); s.push(Number); t.add(Number); y++; } b.addAll(a); Collections.sort(b); System.out.printf("Numbers in order: %s\n",s); System.out.printf("Numbers in reversed order: %s\n",a); System.out.printf("Numbers in ascending order: %s\n",b); } if (choice == 2) { Stack s = new Stack (); LinkedList a = new LinkedList (); LinkedList b = new LinkedList (); TreeSet t = new TreeSet (); int x = 0; int y = 0; System.out.println("Enter how many numbers you want: "); x = input.nextInt(); System.out.println("Enter the numbers you want: "); while (y < x) { Double Number = input.nextDouble(); a.addFirst(Number); s.push(Number); t.add(Number); y++; } b.addAll(a); Collections.sort(b); System.out.printf("Numbers in order: %s\n",s); System.out.printf("Numbers in reversed order: %s\n",a); System.out.printf("Numbers in ascending order: %s\n",b); } if (choice == 3) { Stack s = new Stack(); LinkedList a = new LinkedList(); LinkedList b = new LinkedList(); TreeSet t = new TreeSet(); int x = 0; int y = 0; System.out.println("Enter how many numbers you want: "); x = input.nextInt(); System.out.println("Enter the numbers you want: "); while (y < x) { Double Number = input.nextDouble(); a.addFirst(Number); s.push(Number); t.add(Number); y++; } b.addAll(a); Collections.sort(b); System.out.printf("Numbers in order: %s\n",s); System.out.printf("Numbers in reversed order: %s\n",a); System.out.printf("Numbers in ascending order: %s\n",b); } } }