Solved

Linked list

Posted on 2004-03-29
7
189 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
7 Comments
 
LVL 30

Accepted Solution

by:
Mayank S 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:Mayank S
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:Mayank S
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:Mayank S
ID: 10740801
Why not use java.util.LinkedList instead ;-) ?
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand column That will then direct you to their download page. From that p…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This video teaches viewers about errors in exception handling.

705 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