Solved

Linked list

Posted on 2004-03-29
7
181 Views
Last Modified: 2013-12-14
what should change in the" public object getItem"?? after compile got error. these is code below: thank you
i dont wnat it display all .. i want it get the item " n" 1  then store in temp then add.....


public class LinkedList  {

private class ListCell
  {
  .......  {
  .......  }
  }
      


private ListCell head
private ListCell tail
private int numberInQueue
 protected boolean full;
 
            
public LinkedList()
{

            ......
 }
            
 
public boolean isEmpty()
 {

      
       ......}


      
public void add(Object obj)
{
if (isEmpty())                                   {
  head = new ListCell(obj,head);    .
              tail = null;                    
              numberInQueue++;                         }
                       
        
else                                                {
                  head = new ListCell(obj,head);                      tail = head.Link;                                   numberInQueue++;                                 };
      }


      public Object remove()
      {
      
      ....    }

.


      public int numbElement()
      {    
                       
      ...      }
      
 

  public Object Gethead()
    {
   .....
    }
 
.public LinkedList Gettail()
    {
   ....
   
    };

   
public Object getItem(int n)
    {
    Object obj = new Object();
    LinkedList temporary = new LinkedList();
    temporary.head = head;
    temporary.tail = tail;
    temporary.numberInQueue =numberInQueue ;
    while (!temporary.isEmpty())
      {
      //obj = obj+(temporary.Gethead()).getItem();
      obj = obj+temporary.head.obj;
      temporary = temporary.Gettail();
      };
    return  obj;
    }

}



   
}




0
Comment
Question by:Jacqueline_toh
  • 4
7 Comments
 
LVL 30

Accepted Solution

by:
mayankeagle earned 20 total points
ID: 10703795
>> obj = obj+temporary.head.obj;

What do you want to do here?

And how about some feedback on: http://www.experts-exchange.com/Programming/Programming_Languages/Java/Q_20935647.html

Also:

>> }; // after the while loop

You don't need that semi-colon there.
0
 
LVL 30

Expert Comment

by:mayankeagle
ID: 10703820
Are you importing java.util.* ? Then your code could provide errors because there is an in-built LinkedList class.
0
 
LVL 30

Expert Comment

by:mayankeagle
ID: 10703842
And if that is your code, then it will give a lot more errors. You don't have semi-colons at many places where you need them. And you also have semi-colons at places where you don't need. Can you post your full code and tell us what errors you get and where?
0
 
LVL 4

Expert Comment

by:JK2429
ID: 10740782
If you use the Java Vector class, you would be able to accoplish the same as the linked list class you are trying to create.

http://java.sun.com/j2se/1.3/docs/api/java/util/Vector.html
0
 
LVL 30

Expert Comment

by:mayankeagle
ID: 10740801
Why not use java.util.LinkedList instead ;-) ?
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Systems talking to each other 5 108
Java and GPO 11 47
Where to store the queries for modification of table 4 26
maven project error 5 20
Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This video teaches viewers about errors in exception handling.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now