Text: Linked List Basics (insertFront, insertBack, deleteFront & deleteBack)
Given the following code in main and output, please write the Java program which allows main to work:
public static void main(String[] args) {
/* Start with the empty list. */
LinkedList list = new LinkedList();
// ******INSERTION******
// Insert the values
deleteFront(list);
deleteBack(list);
list = insert(list, 1);
list = insert(list, 2);
list = insert(list, 3);
list = insert(list, 4);
list = insert(list, 5);
list = insert(list, 6);
list = insert(list, 7);
list = insert(list, 8);
// Basic Operations on the LinkedList
printList(list);
insertFront(list, 0);
printList(list);
insertBack(list, 999);
printList(list);
deleteFront(list);
printList(list);
deleteBack(list);
printList(list);
} // end of main
**** UPLOAD TO BLACKBOARD DROP BOX ****
public static void main(String[] args) {
/* Start with the empty list. */
LinkedList list = new LinkedList();
// ******INSERTION******
// Insert the values
deleteFront(list);
deleteBack(list);
list = insert(list, 1);
list = insert(list, 2);
list = insert(list, 3);
list = insert(list, 4);
list = insert(list, 5);
list = insert(list, 6);
list = insert(list, 7);
list = insert(list, 8);
// Basic Operations on the LinkedList
printList(list);
insertFront(list, 0);
printList(list);
insertBack(list, 999);
printList(list);
deleteFront(list);
printList(list);
deleteBack(list);
printList(list);
} // end of main
LinkedList.java*
Compile Messages
jGRASP Messages Run I/O
Interactions
End
-jGRASP exec: java LinkedList
Deleting from the Front... Can not delete front, from an empty list
Deleting from the Back.. Can not delete back, from an empty list
LinkedList: 1 2 3 4 5 6 7 8
Inserting 0 to front...
LinkedList: 0 1 2 3 4 5 6 7 8
Inserting 999 to back..
LinkedList: 0 1 2 3 4 5 6 7 8 999
Deleting from the Front..
LinkedList: 1 2 3 4 5 6 7 8 999
Deleting from the Back..
LinkedList: 1 2 3 4 5 6 7 8
Clear
Help
-jGRASP: operation complete.