[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 193
  • Last Modified:

Linked list

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
Jacqueline_toh
Asked:
Jacqueline_toh
  • 4
1 Solution
 
Mayank SAssociate Director - Product EngineeringCommented:
>> 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
 
Mayank SAssociate Director - Product EngineeringCommented:
Are you importing java.util.* ? Then your code could provide errors because there is an in-built LinkedList class.
0
 
Mayank SAssociate Director - Product EngineeringCommented:
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
 
JK2429Commented:
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
 
Mayank SAssociate Director - Product EngineeringCommented:
Why not use java.util.LinkedList instead ;-) ?
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now