Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. import hsa.Stdin;
  2. class LinkedListAssignment
  3. {
  4. public static void main (String [] args)
  5. {
  6. // Create a List for this course
  7. List CompSci = new List ();
  8. String temp;
  9. System.out.print ("Enter a name to add to the class list: ");
  10. String input = Stdin.readString ();
  11.  
  12.  
  13. //Continuously add names to list until user types "zzz" or "ZZZ"
  14. while (input.compareTo ("zzz") != 0 && input.compareTo ("ZZZ") != 0)
  15. {
  16. CompSci.insert (input);
  17.  
  18. System.out.print ("Enter a name to add to the class list: ");
  19. input = Stdin.readString ();
  20.  
  21. }
  22.  
  23. // print list
  24. CompSci.printList ();
  25.  
  26. }
  27. }
  28.  
  29. class List
  30. {
  31. // This class contains methods that manipulate a linked list
  32. // whose nodes contain strings in their name fields
  33.  
  34.  
  35. // List object contains only a head whose purpose is to
  36. // point to the first object in the list
  37. Student head;
  38.  
  39.  
  40. public List ()
  41. {
  42. // a basic constructor
  43.  
  44. head = null;
  45. }
  46.  
  47.  
  48. public void printList ()
  49. {
  50. // print the contents of a list
  51.  
  52. Student temp = head;
  53. while (temp != null)
  54. {
  55. System.out.println (temp.name);
  56. temp = temp.link;
  57. }
  58. }
  59.  
  60.  
  61. public void insert (String s)
  62. {
  63. // insert a new node containing s in its name field into a list whose nodes
  64. // are kept in increasing lexicographic order
  65.  
  66.  
  67. }
  68.  
  69.  
  70.  
  71.  
  72. class Student
  73. {
  74. // an inner class for nodes of a list
  75.  
  76. String name;
  77. Student link;
  78.  
  79. public Student (String word, Student next)
  80. {
  81. // a simple constructor
  82.  
  83. name = word;
  84. link = next;
  85. }
  86. }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement