Link to home
Start Free TrialLog in
Avatar of kellyputty
kellyputty

asked on

Non-popping linked list

I wrote code that reads lines of text from a file and pushes them on a stack that is a LinkedList.

the file "test.txt" essentialy looks like this:
---------------------------------
top
Abstract: . In this paper, ....
of the features drawn from the document itself.
We also present a preliminary experiment
bottom
--------------------------------
My error is a non-terminating loop the prints to the console "bottom"  over and over.

My error must be in the following part:
while (!listit.isEmpty())
      System.out.println(listit.top()); //linked_list.getFirst()
        listit.pop(); //linked_list.removeFirst()

"bottom" doesn't seem to be popping off causing the loop.

what is my errror?

ASKER CERTIFIED SOLUTION
Avatar of Jim Cakalic
Jim Cakalic
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kellyputty
kellyputty

ASKER

grrr...
Learning Java - O'Reilly pg92 shows while and do while w/o curly braces
and
Eclipse doesn't give you a compilation  error.

but I should have figured that out anyways considering all other expressions do and how else would it know scope.

duh,
thanx.
LOL. Sometimes the obvious isn't so obvious. Good luck. BTW, you knew Java has a Stack class, right?
nope, grrr ;) now I do.  I am in the learning curve...
>> Eclipse doesn't give you a compilation  error.

Because you can have a loop with/ without {} both. If its without {}, then only one statement is in the loop.