Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.44 KB | None | 0 0
  1. package CatenaDoppia;
  2.  
  3. import java.io.Console;
  4. import java.util.Scanner;
  5. import CatenaDoppia.linkedList;
  6. import CatenaDoppia.Node;
  7.  
  8. public class run {
  9.  
  10. public static void main(String[] args)
  11.  
  12. {
  13. Scanner scan = new Scanner(System.in);
  14.  
  15. linkedList list = new linkedList();
  16.  
  17. System.out.println("\nCatena circolare Doppia\n");
  18.  
  19. char carattere;
  20. char carattere2;
  21.  
  22.  
  23.  
  24. do{
  25. System.out.println("Inserire informazione e chiave per il primo nodo Head:");
  26. System.out.print("informazione:");
  27. String informazione0 = scan.next();
  28. System.out.print("chiave:");
  29. int chiave0 = scan.nextInt();
  30.  
  31. while (chiave0 < 1 || chiave0 > 1000000) {
  32. System.out.println("Inserire chiave compresa fra 1 e 10^6");
  33. System.out.print("chiave:");
  34. chiave0 = scan.nextInt();
  35. if (chiave0 >= 1 || chiave0 <= 1000000) {
  36. list.inserireFirst(informazione0, chiave0);
  37. }
  38. }
  39.  
  40. list.inserireFirst(informazione0, chiave0);
  41. list.size++;
  42.  
  43. list.display();
  44. list.getFirst();
  45. System.out.println("\nVuoi continuare? Digita: 'y' oppure 'n'");
  46. System.out.print("Scelta:");
  47. carattere2 = scan.next().charAt(0);
  48.  
  49. while (carattere2 == 'Y' || carattere2 == 'y');{
  50.  
  51. }
  52.  
  53. if (carattere2 == 'N' || carattere2 == 'n') {
  54. System.out.println("\nFine delle operazioni.\nRipartire il programma.");
  55. }
  56. }while(list.getFirst() == null);
  57.  
  58. do {
  59. System.out.println("Operazioni da fare:");
  60. System.out.println("1. inserire all'inizio");
  61. System.out.println("2. inserire nuovo nodo");
  62. System.out.println("3. inserire alla fine");
  63. System.out.println("4. inserire a posizione 'x'");
  64. System.out.println("5. cancellare a posizione 'x'");
  65. System.out.println("6. verifica se la catena è vuota");
  66. System.out.println("7. lunghezza catena");
  67. System.out.println("8. dammi head");
  68. System.out.println("9. dammi tail");
  69. System.out.print("Scelta:");
  70. int choice2 = scan.nextInt();
  71.  
  72. switch (choice2) {
  73. case 1:
  74. System.out.println("Inserire Informazione e chiave per il nodo");
  75. System.out.print("informazione:");
  76. String informazione = scan.next();
  77. System.out.print("chiave:");
  78. int chiave = scan.nextInt();
  79.  
  80. while (chiave < 1 || chiave > 1000000) {
  81. System.out.println("Inserire chiave compresa fra 1 e 10^6");
  82. System.out.print("chiave:");
  83. chiave = scan.nextInt();
  84. if (chiave >= 1 || chiave <= 1000000) {
  85. list.inserireFirst(informazione, chiave);
  86. }
  87. }
  88.  
  89. list.inserireFirst(informazione, chiave);
  90.  
  91. break;
  92. case 2:
  93. int pos = 2;
  94. System.out.println("Inserire informazione e chiave per il nodo");
  95. String informazione4 = scan.next();
  96. int chiave4 = scan.nextInt();
  97. while (chiave4 < 1 || chiave4 > 1000000) {
  98. System.out.println("Inserire chiave compresa fra 1 e 10^6");
  99. System.out.print("chiave:");
  100. chiave = scan.nextInt();
  101. if (chiave >= 1 || chiave <= 1000000) {
  102. list.inserireSecondo(informazione4, chiave, pos);
  103. }
  104. }
  105. list.inserireSecondo(informazione4, chiave4, pos);
  106. break;
  107. case 3:
  108. System.out.println("Inserire Informazione e chiave per il nodo");
  109. System.out.print("informazione:");
  110. String informazione2 = scan.next();
  111. System.out.print("chiave:");
  112. int chiave2 = scan.nextInt();
  113. while (chiave2 < 1 || chiave2 > 1000000) {
  114. System.out.println("Inserire chiave compresa fra 1 e 10^6");
  115. System.out.print("chiave:");
  116. chiave2 = scan.nextInt();
  117. if (chiave2 >= 1 || chiave2 <= 1000000) {
  118. list.inserireLast(informazione2, chiave2);
  119. }
  120. }
  121. list.inserireLast(informazione2, chiave2);
  122.  
  123. break;
  124. case 4:
  125. System.out.println("Inserire Informazione e chiave per il nodo");
  126. int pos2 = 0;
  127. String informazione3 = scan.next();
  128. int chiave3 = scan.nextInt();
  129. while (chiave3 < 1 || chiave3 > 1000000) {
  130. System.out.println("Inserire chiave compresa fra 1 e 10^6");
  131. System.out.print("chiave:");
  132. chiave = scan.nextInt();
  133. if (chiave3 >= 1 || chiave3 <= 1000000) {
  134. list.inserirePosizione(informazione3, chiave3, pos2);
  135. }
  136. }
  137. System.out.print("Inserire posizione: ");
  138. pos2 = scan.nextInt();
  139. if (pos2 < 1 || pos2 > list.getSize())
  140. System.out.println("La posiozione inserita non è valida nella catena");
  141. else
  142. list.inserirePosizione(informazione3, chiave3, pos2);
  143. break;
  144. case 5:
  145. System.out.println("Inserire posizione\n");
  146. int p = scan.nextInt();
  147. if (p < 1 || p > list.getSize())
  148. System.out.println("La posiozione inserita non è valida nella catena ");
  149. else
  150. list.cancellaPosiozione(p);
  151. break;
  152. case 6:
  153. System.out.println("Catena vuota= " + list.isEmpty());
  154. break;
  155. case 7:
  156. System.out.println("Lunghezza = " + list.getSize());
  157. break;
  158. case 8:
  159. System.out.print("First Element :");
  160. list.getFirst();
  161. System.out.println();
  162. break;
  163. case 9:
  164. System.out.print("Last Element :");
  165. list.getLast();
  166. System.out.println();
  167. break;
  168. }
  169. /*
  170. * } /* Display List
  171. */
  172. list.display();
  173. list.getFirst();
  174. System.out.println("\nVuoi continuare? Digita: 'y' oppure 'n'");
  175. System.out.print("Scelta:");
  176. carattere = scan.next().charAt(0);
  177. } while (carattere == 'Y' || carattere == 'y');
  178. if (carattere == 'N' || carattere == 'n') {
  179. System.out.println("\nFine delle operazioni.\nRipartire il programma.");
  180. }
  181. }
  182. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement