Lab 5

\\ Kenny Cruz
\\ CET 3640
\\ Lab #5 – Data Structures
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Stack;
import java.util.TreeSet;

public class DataStructureApp {

public static void main(String[} args) {

Scanner input = new Scanner(System.in);
int opt = 0;
int type= 0;
HashSet Set = new HashSet();
LinkedList Reverse = new LinkedList();
LinkedList Ascend = new LinkedList();
Stack Stack = new Stack();
TreeSet treeset = new TreeSet();

do {

System.out.println(“MENU”);
System.out.println(“Please select a data type or exit:”);
System.out.println(” (1) String \n (2) Double \n (3) Integer “);
System.out.println(” (4) Exit”);

type = input.nextInt();

if(type == 1)
{
int current = 0;
System.out.print(“Enter the amount of strings: “);
int total = input.nextInt();

while(current < total) {

String text = input.next();
Reverse.addFirst(text);
Stack.push(text);
treeset.add(text);
Set.add(text);
current++;
}
}

else if(type == 2)
{
int current = 0;
System.out.print("Enter amount of doubles: ");
int total = input.nextInt();

while(current < total) {

double text = input.nextDouble();
Reverse.addFirst(text);
Stack.push(text);
treeset.add(text);
Set.add(text);
current++;
}
}

else if(type == 3)
{
int current = 0;
System.out.print("Enter Amount of Integers: ");
int total = input.nextInt();

while(current < total) {

Integer text = input.nextInt();
Reverse.addFirst(text);
Stack.push(text);
treeset.add(text);
Set.add(text);
current++;
}
}
Ascend.adddAll(Reverse);
Collections.sort(Ascend);
type = 'n';
if (type == 4)
{
System.exit(0);
}
} while (type != 'n');

System.out.println("Elements entered in order:" + Stack);
System.out.println("Elements entered in opposite order:" + Reverse);
System.out.println("Elements entered in ascending order:" + Ascend);
System.out.println("Elements entered Without repetition:" + Set);
}
}

Leave a Reply

Your email address will not be published. Required fields are marked *