Advertisement
Guest User

Untitled

a guest
Apr 25th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. public class CircularlyLinkedListTest {
  2.  
  3. public static void main(String[] args) {
  4. System.out.println("B. Marquez's CircularlyLinkedList");
  5.  
  6. /* Create new CLL containing Strings*/
  7. CircularlyLinkedList<String> list1 = new CircularlyLinkedList<>();
  8. /* Create new array to insert into the CLL */
  9. String[] add1 = {"hello", "new", "world", "I'm", "bob"};
  10.  
  11. System.out.println("\nAdding a string array with 5 items to list1...");
  12.  
  13. for (int i = 0; i < add1.length; i++) { // adds all the items in the array into the list
  14. list1.add(add1[i]);
  15. }
  16. /* Print the length and items of the list to verify that all items have been added */
  17. System.out.print("list1 now contains " + list1.length() + " items.\nPrint list1: ");
  18. list1.print();
  19. /* Remove from the list one by one until there's nothing in the list, each time printing the list again to verify */
  20. System.out.print("\nRemoving from the list until it's empty...\n");
  21.  
  22. while (list1.length() != 0) { // while there's something in the list
  23. list1.remove();
  24. System.out.print("list1 now contains " + list1.length() + " items.\nPrint list1: ");
  25. list1.print();
  26. }
  27.  
  28. /* New CLL containing Integers */
  29. CircularlyLinkedList<Integer> list2 = new CircularlyLinkedList<Integer>();
  30. /* New Integer array to insert into the CLL */
  31. Integer[] add2 = {1, 2, 3, 4, 5, 6};
  32.  
  33. System.out.println("\n\nAdding an integer array with 6 items to list2...");
  34.  
  35. for (int i = 0; i < add2.length; i++)
  36. list2.add(add2[i]);
  37. /* Check where the cursor is currently pointing at [testing .getData() and .advance()] */
  38. System.out.println("Currently, the cursor of list2 is pointing to " + list2.getData());
  39.  
  40. list2.advance(); // moves the cursor to the next item
  41.  
  42. System.out.println("After using list2.advance(), list2's cursor is now pointing to " + list2.getData());
  43. System.out.println("list2 contains: ");
  44. list2.print();
  45.  
  46. System.out.println("--End of program--");
  47.  
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement