Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class CircularlyLinkedListTest {
- public static void main(String[] args) {
- System.out.println("B. Marquez's CircularlyLinkedList");
- /* Create new CLL containing Strings*/
- CircularlyLinkedList<String> list1 = new CircularlyLinkedList<>();
- /* Create new array to insert into the CLL */
- String[] add1 = {"hello", "new", "world", "I'm", "bob"};
- System.out.println("\nAdding a string array with 5 items to list1...");
- for (int i = 0; i < add1.length; i++) { // adds all the items in the array into the list
- list1.add(add1[i]);
- }
- /* Print the length and items of the list to verify that all items have been added */
- System.out.print("list1 now contains " + list1.length() + " items.\nPrint list1: ");
- list1.print();
- /* Remove from the list one by one until there's nothing in the list, each time printing the list again to verify */
- System.out.print("\nRemoving from the list until it's empty...\n");
- while (list1.length() != 0) { // while there's something in the list
- list1.remove();
- System.out.print("list1 now contains " + list1.length() + " items.\nPrint list1: ");
- list1.print();
- }
- /* New CLL containing Integers */
- CircularlyLinkedList<Integer> list2 = new CircularlyLinkedList<Integer>();
- /* New Integer array to insert into the CLL */
- Integer[] add2 = {1, 2, 3, 4, 5, 6};
- System.out.println("\n\nAdding an integer array with 6 items to list2...");
- for (int i = 0; i < add2.length; i++)
- list2.add(add2[i]);
- /* Check where the cursor is currently pointing at [testing .getData() and .advance()] */
- System.out.println("Currently, the cursor of list2 is pointing to " + list2.getData());
- list2.advance(); // moves the cursor to the next item
- System.out.println("After using list2.advance(), list2's cursor is now pointing to " + list2.getData());
- System.out.println("list2 contains: ");
- list2.print();
- System.out.println("--End of program--");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement