null previousnext currentnext current currentnext size

Null previousnext currentnext current currentnext size

This preview shows page 6 - 7 out of 7 pages.

while(current != null && current.data.equals(item)){ previous.next = current.next; current = current.next; --size; } if(current != null){ previous = current; current = current.next; } } if(tail != null && tail.data.equals(item)){ tail = previous; if(previous.next != null){ previous.next = null; --size; } } } public Object retrieve(int pos){ Link current = head; for(int i=1;i<pos;++i){ current = current.next; } return current.data; } public List find(Object item){ List index = new List(); Link current = head; Integer ix; int kx = 1; do{ if(current.data.equals(item)){ ix = kx; index.insertAtEnd(ix); } current = current.next; ++kx; }while(current != null); return index; } public int getSize(){ return size; } public String toString(){ String result = ""; Link current = head;
Image of page 6
while(current != null){ result += current.data.toString() + " "; current = current.next; } return result; } } class Inventory{ private String _name; private int _quantity; private double _price; public Inventory(String name, int quantity, double price){ _name = name; _quantity = quantity; _price = price; } public boolean equals(Object other){ if(_name.equals((String) other)){ return true; } else{ return false; } } public double getSum(){ return _quantity * _price; } public String toString(){ String result = "Item: " + _name + " Quantity: " + _quantity + " Price: $" + _price + "\n"; return result; } } class Link{ public Object data; public Link next; }
Image of page 7

You've reached the end of your free preview.

Want to read all 7 pages?

  • Spring '14

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture