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?
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.
listit.pop(); //linked_list.removeFirst(
"bottom" doesn't seem to be popping off causing the loop.
what is my errror?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
LOL. Sometimes the obvious isn't so obvious. Good luck. BTW, you knew Java has a Stack class, right?
ASKER
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.
Because you can have a loop with/ without {} both. If its without {}, then only one statement is in the loop.
ASKER
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.