Guest User

Untitled

a guest
Feb 25th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.65 KB | None | 0 0
  1. /*
  2. * Name = Abdulmohsen ali asiri
  3. * ID = 36110218
  4. */
  5. package testintegerdll;
  6.  
  7. /**
  8. *
  9. * @author asiri
  10. */
  11. import java.util.Scanner;
  12.  
  13. public class TestIntegerDLL {
  14.  
  15. public static void main(String[] args) {
  16. DLL<Integer> list = new DLL<Integer>();
  17. int option, target, target2;
  18.  
  19. Scanner stdin = new Scanner(System.in);
  20.  
  21. do {
  22. System.out.println("\n***************************");
  23. System.out.println(" Testing Integer DLL ");
  24. System.out.println("***************************");
  25. System.out.println("1. Add Node at Head");
  26. System.out.println("2. Add Node at Tail");
  27. System.out.println("3. Print All Nodes");
  28. System.out.println("4. Delete Node from Head");
  29. System.out.println("5. Delete Node from Tail");
  30. System.out.println("6. Delete a Given Node");
  31. System.out.println("7. Search for a Node");
  32. System.out.println("8. Return an element at a given index");
  33. System.out.println("9. Return the index of a given element");
  34. System.out.println("10. Replace the element at a given index");
  35. System.out.println("11. Insert an element at an index");
  36. System.out.println("12. Delete an element");
  37. System.out.println("13. Quit");
  38.  
  39. System.out.print("\nSelect an Option [1...13] : ");
  40. option = stdin.nextInt();
  41.  
  42. switch (option) {
  43. case 1:
  44. System.out.print("Enter the element to add at Head: ");
  45. list.addToHead(stdin.nextInt());
  46. break;
  47.  
  48. case 2:
  49. System.out.print("Enter the element to add at Tail: ");
  50. list.addToTail(stdin.nextInt());
  51. break;
  52.  
  53. case 3:
  54. list.printAll();
  55. break;
  56.  
  57. case 4:
  58. list.deleteFromHead();
  59. break;
  60.  
  61. case 5:
  62. list.deleteFromTail();
  63. break;
  64.  
  65. case 6:
  66. System.out.print("Enter node to delete: ");
  67. target = stdin.nextInt();
  68.  
  69. if (list.find(target) != null) {
  70. list.delete(target);
  71. System.out.println("The element " + target + " has been deleted");
  72. } else {
  73. System.out.println("Sorry, element " + target + " is not in the list");
  74. }
  75. break;
  76.  
  77. case 7:
  78. System.out.print("Enter node to search for: ");
  79. target = stdin.nextInt();
  80.  
  81. if (list.find(target) != null) {
  82. System.out.println("The element " + target + " is in the list");
  83. } else {
  84. System.out.println("Sorry, element " + target + " is not in the list");
  85. }
  86. break;
  87.  
  88. case 8:
  89. System.out.print("Enter the index: ");
  90. target = stdin.nextInt();
  91. System.out.println("The element at index["+target+"] is: "+list.get(target));
  92. break;
  93.  
  94.  
  95. case 9:
  96. System.out.print("Enter the element to return index: ");
  97. target = stdin.nextInt();
  98. System.out.println("The index of this element is: "+list.indexOf(target));
  99. break;
  100.  
  101. case 10:
  102. System.out.print("Enter the index to replace at: ");
  103. target = stdin.nextInt();
  104. System.out.print("Enter the element for replacment: ");
  105. target2 = stdin.nextInt();
  106. list.replace(target, target2);
  107. break;
  108.  
  109. case 11:
  110. System.out.print("Enter the index to insert at: ");
  111. target = stdin.nextInt();
  112. System.out.print("Enter the element for insertion: ");
  113. target2 = stdin.nextInt();
  114. list.insertAt(target, target2);
  115. break;
  116.  
  117. case 12:
  118. System.out.print("Enter the index to delete: ");
  119. target = stdin.nextInt();
  120. System.out.println(list.deleteAt(target)+" have been deleted successfully!");
  121. break;
  122.  
  123. } //end of switch
  124.  
  125. } while (option != 13);
  126. } //end of main
  127.  
  128. }
Add Comment
Please, Sign In to add comment