Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Name = Abdulmohsen ali asiri
- * ID = 36110218
- */
- package testintegerdll;
- /**
- *
- * @author asiri
- */
- import java.util.Scanner;
- public class TestIntegerDLL {
- public static void main(String[] args) {
- DLL<Integer> list = new DLL<Integer>();
- int option, target, target2;
- Scanner stdin = new Scanner(System.in);
- do {
- System.out.println("\n***************************");
- System.out.println(" Testing Integer DLL ");
- System.out.println("***************************");
- System.out.println("1. Add Node at Head");
- System.out.println("2. Add Node at Tail");
- System.out.println("3. Print All Nodes");
- System.out.println("4. Delete Node from Head");
- System.out.println("5. Delete Node from Tail");
- System.out.println("6. Delete a Given Node");
- System.out.println("7. Search for a Node");
- System.out.println("8. Return an element at a given index");
- System.out.println("9. Return the index of a given element");
- System.out.println("10. Replace the element at a given index");
- System.out.println("11. Insert an element at an index");
- System.out.println("12. Delete an element");
- System.out.println("13. Quit");
- System.out.print("\nSelect an Option [1...13] : ");
- option = stdin.nextInt();
- switch (option) {
- case 1:
- System.out.print("Enter the element to add at Head: ");
- list.addToHead(stdin.nextInt());
- break;
- case 2:
- System.out.print("Enter the element to add at Tail: ");
- list.addToTail(stdin.nextInt());
- break;
- case 3:
- list.printAll();
- break;
- case 4:
- list.deleteFromHead();
- break;
- case 5:
- list.deleteFromTail();
- break;
- case 6:
- System.out.print("Enter node to delete: ");
- target = stdin.nextInt();
- if (list.find(target) != null) {
- list.delete(target);
- System.out.println("The element " + target + " has been deleted");
- } else {
- System.out.println("Sorry, element " + target + " is not in the list");
- }
- break;
- case 7:
- System.out.print("Enter node to search for: ");
- target = stdin.nextInt();
- if (list.find(target) != null) {
- System.out.println("The element " + target + " is in the list");
- } else {
- System.out.println("Sorry, element " + target + " is not in the list");
- }
- break;
- case 8:
- System.out.print("Enter the index: ");
- target = stdin.nextInt();
- System.out.println("The element at index["+target+"] is: "+list.get(target));
- break;
- case 9:
- System.out.print("Enter the element to return index: ");
- target = stdin.nextInt();
- System.out.println("The index of this element is: "+list.indexOf(target));
- break;
- case 10:
- System.out.print("Enter the index to replace at: ");
- target = stdin.nextInt();
- System.out.print("Enter the element for replacment: ");
- target2 = stdin.nextInt();
- list.replace(target, target2);
- break;
- case 11:
- System.out.print("Enter the index to insert at: ");
- target = stdin.nextInt();
- System.out.print("Enter the element for insertion: ");
- target2 = stdin.nextInt();
- list.insertAt(target, target2);
- break;
- case 12:
- System.out.print("Enter the index to delete: ");
- target = stdin.nextInt();
- System.out.println(list.deleteAt(target)+" have been deleted successfully!");
- break;
- } //end of switch
- } while (option != 13);
- } //end of main
- }
Add Comment
Please, Sign In to add comment