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
Solved

Linked list

Posted on 2004-03-29
7
187 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:
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Weekend adv creator 3 51
java stored proc example 9 44
Bot application - advice 3 37
swing controls 2 15
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
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…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

791 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