rcossy1023 0 Newbie Poster

Sorry about the double post but i dont know if you can delete posts?

Anyway I need to have a circular linked stack where after 5 pushs the 6th push goes into front and replaces the data starting at front and going back. So theoretically if I put in a 6th entry the 1st entry will not show because it has been replaced by the 6th?? right???

I tried this but yet my 1st entry still shows....heres my code:

public void push(T element) {
		LinearNode<T> node = new LinearNode<T>(element);
		if (count == 0)
			front = rear = node;
		if (count > 5) {
			front = null;
			node.setNext(front);
			front = node;
			

		} else {

			node.setNext(rear);
			rear = node;
		}
		count++;
	}

	

	public T pop() {
		T result = rear.getElement();
		rear = rear.getNext();
		return result;

	}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.