// declare nodes and string for user input
Node node, head;
String userData;
// initialise the head to null
head = null;
// loop to create new nodes for the linked list using user data do { System.out.print("What name would you like stored? (\"quit\" to end) ");
userData = stdin.readLine();
// create a new node if the user has not decided to quit if(!userData.equals("quit")) {
node = new Node (userData);
node.next = head;
// update the head to point to the new front of the list
head = node;
} } while(!userData.equals("quit")); // loop continues until "quit" selected
// print a blank line and reset pointer to start of linked list System.out.println();
node = head;
// loop through entire linked list to display its contents do { System.out.println(node.data);
node = node.next;
} while(node != null); // loop until the end of lists is reached } }
What do I need to do in order to remove a node (as specified by the user)?
Sponsor Sponsor
Panphobia
Posted: Wed Dec 05, 2012 11:27 pm Post subject: RE:Removing an element from a Linked List