| | |
Linked List help
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
The program compiles but is not run right can somebody help plz? There are two parts a class and a main.
--------------------------------------MAIN----------------------------------
java Syntax (Toggle Plain Text)
public class LinkedList56 { private class node{ int data; node next; } //create an empty linked list public LinkedList56(){ first = null; } //return true if the list is empty, otherwise return false public boolean empty(){ if(first == null){ return true; } else return false; } //insert a value x at the end public void InsertAtEnd(LinkedList56 x, int a){ //create new node node q = new node(); node p = new node(); q.data = a; q.next = null; //empty list if(first == null){ first = q; } //list is not empty else p = first; while(p.next != null){ p = p.next; } p.next = q; } //if value x is in the list, romove x public void Delete(int a){ node pointer = new node(); node doublepointer = new node(); pointer = first; doublepointer = pointer.next; while(doublepointer.data != a){ pointer = doublepointer.next; //preptr = preptr.next; doublepointer = doublepointer.next; } pointer = doublepointer.next; } //Display the data values in the linked list public void Display(){ System.out.println(); } //pointer to the first node in the list private node first; }
--------------------------------------MAIN----------------------------------
java Syntax (Toggle Plain Text)
public class Program2 { public static void main(String[] args)throws Exception{ LinkedList56 x = new LinkedList56(); for(int a = 1; a < 10; a++){ if((a%2 == 0)){ x.InsertAtEnd(x,a); x.Display(); x.Delete(2); System.out.println("list after deleting 2:"); x.Display(); x.Delete(6); System.out.println("list after deleting 6:"); x.Display(); if(!x.empty()){ System.out.println("List is not empty"); } } } } }
Thought it would be easier if we all chipped in and helped you out but it would beat the actual purpose of learning things.
If you are still in the stages of developing your programs in a text editor, litter your program with log statements at appropriate places and find the point wherein the program starts behaving in an unexpected manner. If using an IDE like Eclipse, debug your application and inspect the variables at run time. Guesswork should not be the approach here...
If you are still in the stages of developing your programs in a text editor, litter your program with log statements at appropriate places and find the point wherein the program starts behaving in an unexpected manner. If using an IDE like Eclipse, debug your application and inspect the variables at run time. Guesswork should not be the approach here...
Last edited by ~s.o.s~; Aug 29th, 2008 at 12:04 am.
I don't accept change; I don't deserve to live.
Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
![]() |
Similar Threads
- Removing an item from head of linked list (C)
- help implementing singly linked list (C++)
- How to read in a sentence and insert in to linked list? (C++)
- Linked List using pointers (C++ ADT) (C++)
- Why doesn't this remove the last node in a linked list? (C++)
- Cannot figure out how to implement linked list and rbtree for a project! (Java)
- Linked List (C++)
- help by sorting a simply linked list (C)
Other Threads in the Java Forum
- Previous Thread: I need Extract Email from html or doc code
- Next Thread: Need Help
| Thread Tools | Search this Thread |
Tag cloud for Java
addressbook android api apple applet application arguments array arrays automation binary bluetooth button calculator chat class classes client code columns component converter database draw eclipse error errors event exception file fractal ftp game givemetehcodez graphics gridlayout gui helpwithhomework html ide image inetaddress input integer j2me japplet java javaprojects jme jmf jni jpanel julia link linux list loop map method methods midlethttpconnection mobile netbeans newbie number objects openjavafx oracle php print problem program programming project projects recursion rim scanner screen server set signing size smart sms socket sort sql storm string support swing test threads time tree unlimited variablebinding webservices windows






