Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Linked list

Posted on 2004-03-29
7
Medium Priority
?
192 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 80 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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
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…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

618 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