custom linkedList implementation

Computing systems are concerned with the storage and retrieval of information.For systems to be economical the data must be organized (into data structures) in such a way as to support efficient manipulation (by algorithms).Choosing the wrong algorithms and data structures makes a program slow at best and unmaintainable and insecure at worst.

Lets take an example of purchase order of an e-commerce store. If purchase order implemented as custom linkedlist then we can take benefit of

a) constant-time insertions/deletions from the list
b) maintaining many versions of purchase order without any additional complexity.
c) to insert items in the middle of the list (such as a priority queue)
d) many priority queue based operation
e) In-memory operations

below is one such implementation

package com;

import java.util.Iterator;

public class LinkedListDemo {

	public static void main(String[] args) {

		LinkedList lnkls = new LinkedList();
		System.out.println("Total added items :" + lnkls.size);
		Iterator<LinkedList.Node> it = lnkls.iterator();

		System.out.println("****** Items of LinkedList ******");

		while (it.hasNext()) {


class LinkedList implements Iterable<LinkedList.Node>, Iterator<LinkedList.Node> {

	Node head;
	Node lastNode;
	Node visitorNode;

	int size = 0;
	int visited = 0;

	public LinkedList() {

	public void add(Object o) {
		Node newNode = new Node(o);

		if (this.head == null) {
			this.lastNode = this.head = newNode;
		} else { = newNode;
			this.lastNode = newNode;
		System.out.println("Added " + newNode);

	public Iterator<LinkedList.Node> iterator() {
		visitorNode = lastNode = head;
		return this;

	public boolean hasNext() {
		if (visited++ < size)
			return true;
			return false;

	public Node next() {
		Node visitedNode = lastNode;
		lastNode =;
		return visitedNode;

	class Node {

		Object objValue;
		Node next;

		public Node(Object o) {
			this.objValue = o; = null;

		public String toString() {
			return objValue.toString();

 // additional operational and supportive APIs for custom linkedlist