Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy cant I remove a node from my circular linked list by allocating it to the next node?
    text
    copied!<p>This program accepts user data (names) and outputs the information on the screen. Then asks the user which to name to remove from the linked list.</p> <p>I'm having difficulty with my program involving deleting. I cant seem to remove the nodes because of an error I'm reviving with "next" and "prev" (See below).</p> <pre><code>public static void main (String str[]) throws IOException { BufferedReader stdin = new BufferedReader (new InputStreamReader (System.in)); Node node, head, tail; // node is where string data is kept String name, delete; int count = 0; head = null; // initialize the head and tail to null tail = null; System.out.print ("Enter a name. Type q to end inputting."); name = stdin.readLine (); node = new Node (name); node.next = head; head = node; tail = node; contestant = null; do // loop to create new nodes for the linked list using user data { System.out.print ("Enter a name. Type q to end."); name = stdin.readLine (); // create a new node if the user has not decided to quit if (!contestant.equals ("q")) { node = new Node (name); node.next = head; count++; head = node; // update the head to point to the new front of the list } } while (!contestant.equals ("q")); // loop continues until "q" selected System.out.println (); do // display contestants { System.out.println (node.data); node = node.next; } while (node != null); // loop until the end of lists is reached //////////////////////////////////////////Delete/////////////////////////////////////////// boolean Delete; // check to see if deleted Node listNode; // node to delete System.out.println ("Enter a node to be removed:"); delete = stdin.readLine (); listNode = new Node (delete); Node temp = listNode; do { if (temp.listNode () == node) { node.prev = temp.previous (); node.next = temp.next (); if (prev != listNode.next) { prev.next () = next; next.previous () = prev; // removed return true; } else { return false; // only one node } temp = temp.next (); } } while (temp != listNode); // couldnt remove return false; } } </code></pre> <p>The Node class:</p> <pre><code>public class Node { Node next, prev; String data; public Node (String data) { this.data = data; } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload