Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: Circular Linked List---Need Help ASAP (before midnight)

  1. #1
    Junior Member The Dark Mathematician's Avatar
    Join Date
    Apr 2011
    Posts
    5
    My Mood
    Where
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Circular Linked List---Need Help ASAP (before midnight)

    I really need help with the code of a Circular Linked List...it seems I suck at writing code. It has errors gallore and I would appreciate any help I could get. Unfortunately it needs to be done by midnight tonight so...PLEASE HELP ME!!!!!!! Here is what I got so far. If you can help me in time I will forever be your best friend!
    import java.util.Scanner;
    public interface CircularListADT<T> {
    	public int count;
    	public Node top;
     
    	public void insertNode(T value){
    		Node newNode = new Node();
    		top.setNext(newNode);
    		top = newNode;
    	}
     
    	public boolean deleteNode(T value){
    		top = top.getNext();
    	}
     
    	public Node getCurrentNode(){
    		return top;
    	}
     
    	public Node forward(){
    		Node<T> current = top;
    		current = top.getNext();
    		return current;
    	}
    	/**
    	 * Move the current node reference backward to its previous node,
    	 * and return the updated current node reference
    	 * @return
    	 */
    	public Node backword(){
    	}
    	/**
    	 * Find if the list hold a node with its element being 
    	 * the passed value
    	 * @param value
    	 * @return null if no such node exists, or the node 
    	 * reference that points to the object with the same element
    	 */
    	public Node search(T value){
     
    	  }
     
    	public int size(){
    		  int count = 0;
    		  Node<T> t = top;
    		  while(t!=top){
    			  count++;
    			  t=t.getNext();
    		  }
    		  if(t.getNext()==top){
    			  break;
    		  }
    		return count;
    	}
     
    	public String toString(){
    		String result = "";
    		Node<T> current = top;
    		while (current != null) {
    			result = result + (current.getElement()).toString() + "\n";
    			current = current.getNext();
    		}
    		return result;
    	}
    }
     
     
     
    public class Node<T> {
     
    	private Node<T> next;
     
    	private T element;
     
    	public Node() {
    		next = null;
    		element = null;
    	}
     
    	public Node(T elem) {
    		next = null;
    		element = elem;
    	}
     
    	public Node<T> getNext() {
    		return next;
    	}
     
    	public void setNext(Node<T> node) {
    		next = node;
    	}
     
    	public T getElement() {
    		return element;
    	}
     
    	public void setElement(T elem) {
    		element = elem;
    	}
     
    	public String toString(){
    		return ""+element + " with the next node of "+next.getElement();
    	}
    }
     
     
     
     
    public class CircularListDriver {
    	public static void main(String[]args){
    		String operation = "none";
    		Scanner scan = new Scanner(System.in);
    		System.out.println("Select an option: ");
    		operation = scan.next();
     
    		if(operation.equalsIgnoreCase("insert"))
    			insertNode();
    		else if(operation.equalsIgnoreCase("delete"))
    			deleteNode();
    		else if(operation.equalsIgnoreCase("current node"))
    			getCurrentNode();
    		else if(operation.equalsIgnoreCase("forward"))
    			forward();
    		else if(operation.equalsIgnoreCase("backword"))
    			backward();
    		else if(operation.equalsIgnoreCase("search"))
    			search();
    		else if(operation.equalsIgnoreCase("size"))
    			size();
    	}
    }
    Last edited by helloworld922; April 15th, 2011 at 06:06 PM.


  2. #2
    Forum Squatter newbie's Avatar
    Join Date
    Nov 2010
    Location
    North Wales
    Posts
    661
    My Mood
    Stressed
    Thanks
    28
    Thanked 115 Times in 106 Posts
    Blog Entries
    1

    Default Re: Circular Linked List---Need Help ASAP (before midnight)

    Wrap your code in highlight tags as seen in my signature and post the exact issues and exception messages your having.
    Nobody wants to have to compile and run your code in order to discover the issues.
    Please use [highlight=Java]//code goes here...[/highlight] tags when posting your code

  3. #3
    Junior Member The Dark Mathematician's Avatar
    Join Date
    Apr 2011
    Posts
    5
    My Mood
    Where
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Circular Linked List---Need Help ASAP (before midnight)

    Sorry...I am new to this. Here it is wrapped in highlight tags. Please Help...I beg of thee.

    import java.util.Scanner;
    public interface CircularListADT<T> {
    public int count;
    public Node top;
     
    public void insertNode(T value){
    Node newNode = new Node();
    top.setNext(newNode);
    top = newNode;
    }
     
    public boolean deleteNode(T value){
    top = top.getNext();
    }
     
    public Node getCurrentNode(){
    return top;
    }
     
    public Node forward(){
    Node<T> current = top;
    current = top.getNext();
    return current;
    }
    /**
    * Move the current node reference backward to its previous node,
    * and return the updated current node reference
    * @return
    */
    public Node backword(){
    }
    /**
    * Find if the list hold a node with its element being 
    * the passed value
    * @param value
    * @return null if no such node exists, or the node 
    * reference that points to the object with the same element
    */
    public Node search(T value){
     
    }
     
    public int size(){
    int count = 0;
    Node<T> t = top;
    while(t!=top){
    count++;
    t=t.getNext();
    }
    if(t.getNext()==top){
    break;
    }
    return count;
    }
     
    public String toString(){
    String result = "";
    Node<T> current = top;
    while (current != null) {
    result = result + (current.getElement()).toString() + "\n";
    current = current.getNext();
    }
    return result;
    }
    }
     
     
     
    public class Node<T> {
     
    private Node<T> next;
     
    private T element;
     
    public Node() {
    next = null;
    element = null;
    }
     
    public Node(T elem) {
    next = null;
    element = elem;
    }
     
    public Node<T> getNext() {
    return next;
    }
     
    public void setNext(Node<T> node) {
    next = node;
    }
     
    public T getElement() {
    return element;
    }
     
    public void setElement(T elem) {
    element = elem;
    }
     
    public String toString(){
    return ""+element + " with the next node of "+next.getElement();
    }
    }
     
     
     
     
    public class CircularListDriver {
    public static void main(String[]args){
    String operation = "none";
    Scanner scan = new Scanner(System.in);
    System.out.println("Select an option: ");
    operation = scan.next();
     
    if(operation.equalsIgnoreCase("insert"))
    insertNode();
    else if(operation.equalsIgnoreCase("delete"))
    deleteNode();
    else if(operation.equalsIgnoreCase("current node"))
    getCurrentNode();
    else if(operation.equalsIgnoreCase("forward"))
    forward();
    else if(operation.equalsIgnoreCase("backword"))
    backward();
    else if(operation.equalsIgnoreCase("search"))
    search();
    else if(operation.equalsIgnoreCase("size"))
    size();
    }
    }

  4. #4
    Junior Member The Dark Mathematician's Avatar
    Join Date
    Apr 2011
    Posts
    5
    My Mood
    Where
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Circular Linked List---Need Help ASAP (before midnight)

    The issues I am having are that the Method head names are saying that they do not specify a body. I am also having trouble figuring out how to write the code for the backword method and the search method, the descriptions are in the comments. I am also having trouble with allowing the user to select the methods in the main method. I am not sure exactly what I am doing wrong and I would REALLY appreciate any help I could get.

  5. #5
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Circular Linked List---Need Help ASAP (before midnight)

    First, the code posted is still a bit hard to read with the lack of indenting.

    Second, you've got quite a few questions associated with this, and its hard to direct all of them. That being said, there are some glaring errors that indicate you should research some fundamentals. For example, an interface is defined as containing methods which are not implemented. As CircularListADT is defined as an interface you can define CircularListADT with non-implemented methods, or change its definition to a class ( see What Is an Interface? (The Java™ Tutorials > Learning the Java Language > Object-Oriented Programming Concepts) ). Another example: in main you attempt to call insertNode without parameters, but that method is defined to take a parameter (see Passing Information to a Method or a Constructor (The Java™ Tutorials > Learning the Java Language > Classes and Objects) ).

    Lastly, for future reference, urgency is relative. You may have priorities, but so do all other contributors to the forums - thus marking threads as ASAP could be interpreted as disrespectful to others asking questions and those providing trying to provide help.
    Last edited by copeg; April 15th, 2011 at 09:49 PM.

  6. #6
    Junior Member The Dark Mathematician's Avatar
    Join Date
    Apr 2011
    Posts
    5
    My Mood
    Where
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Circular Linked List---Need Help ASAP (before midnight)

    Sorry...I did not mean for it to be disrespectful. I will mark it as solved because I do not know how to close the thread. Sorry for any trouble I might have caused.

Similar Threads

  1. Help with a doubly linked circular list
    By TeamRival in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 3rd, 2011, 10:59 PM
  2. linked list help
    By tjoney in forum What's Wrong With My Code?
    Replies: 6
    Last Post: March 3rd, 2011, 06:54 PM
  3. [SOLVED] Linked List Help
    By lieles in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 4th, 2011, 10:32 PM
  4. Help with linked list
    By joecool594 in forum Collections and Generics
    Replies: 3
    Last Post: November 28th, 2010, 12:33 PM
  5. circular linked list
    By student123xyz in forum Collections and Generics
    Replies: 4
    Last Post: August 19th, 2009, 10:40 AM

Tags for this Thread