Featured image of post The ordered list implemenatation

The ordered list implemenatation

A simple guide on ordered list implementation

The ordered list is the collection of items where each items maintains it’s position unlike Unordered list. The ordering of the item is typically ascending and descending and we assume that items are ordered with meaningful comparison operation.

Operations of Ordered List

  1. OrderedList(): Creates new ordered list that is empty. Returns empty list.
  2. add(item) : adds a new item to the list maintaining the order. Returns nothing.
  3. remove(item): removes the item from the list , assuming the item is present in the list. Returns boolean(True or False)
  4. search(item): Searches for the item in the list. Returns boolean(True of False).
  5. is_empty(): Test to see whether the list is empty. Returns boolean.
  6. size(): Returns the number of the item in the list.
  7. index(item): Returns the position of the item in the list.
  8. pop(): Removes and returns the last item in the list.
  9. pop(pos): Removes and returns the position at the position pos.

Image Description

How to search in the list?

Since the list is ordered it is pretty straight-forward to search through the list. There are two things we need to consider, item the data or the value that we are searching for and current.data the data or the value of the current node.

comments powered by Disqus