473,387 Members | 3,684 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

stack lifo

oll3i
679 512MB
Expand|Select|Wrap|Line Numbers
  1. @Override
  2. public IAbstractQueryResult pop () { return lifo.pop();
  3. }
In main

Expand|Select|Wrap|Line Numbers
  1. IAbstractQueryResult resLeft = qres.pop()
here i get empty stack exception

Thank YOU
Oct 31 '13 #1
3 2597
r035198x
13,262 8TB
You are trying to get an element from an empty stack.

Either your logic is wrong and pop is being called when it's not supposed to be called or you should check to see if there is an element before popping.
Oct 31 '13 #2
oll3i
679 512MB
Expand|Select|Wrap|Line Numbers
  1. QResStack qres = new QResStack();
  2. qres.push(new IntegerResult(1)); // (1)
  3. qres.push(new IntegerResult(2)); // (2)
  4. { // (3)
  5. IAbstractQueryResult resRight = qres.pop();
  6. IAbstractQueryResult resLeft = qres.pop();
  7. //iloczyn kartezjanski - operator przecinka
  8. IBagResult commaRes = QExecUtils.cartesianProduct(resLeft,resRight);
  9. qres.push(commaRes);
  10. }
  11. qres.push(new IntegerResult(3)); // (4)
  12. qres.push(new IntegerResult(4)); // (5)
  13. { // (6)
  14. IntegerResult resRight = (IntegerResult) qres.pop();
  15. IntegerResult resLeft = (IntegerResult) qres.pop();
  16. IntegerResult plusRes = new IntegerResult((Integer)resLeft.getValue() + (Integer)resRight.getValue());
  17. qres.push(plusRes);
  18. }
  19. { // (7)
  20. IAbstractQueryResult resRight = qres.pop();
  21. IAbstractQueryResult resLeft = qres.pop();
at the last line i get
run:
Exception in thread "main" java.util.EmptyStackException
at java.util.Stack.peek(Stack.java:102)
at java.util.Stack.pop(Stack.java:84)
at s4409_s4409_pr2.QResStack.pop(QResStack.java:20)
at s4409_s4409_pr2.S4409_s4409_pr2.main(S4409_s4409_p r2.java:51)
Java Result: 1
Nov 1 '13 #3
Nepomuk
3,112 Expert 2GB
Without knowing the exact implementation of your stack it's difficult to tell; I implemented a simple stack, used it with your code and it works fine. Maybe debug the QResStack function? It seems that whatever internal data collection you're using there's no element in it at the last line.
Nov 3 '13 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

15
by: Andrew | last post by:
Last night I was reading about implementing my own stack. The example given pushes items on and off the stack at the start and end of each procedure (ie. in a std module). What's not so clear is...
4
by: anonymous | last post by:
Thanks your reply. The article I read is from www.hakin9.org/en/attachments/stackoverflow_en.pdf. And you're right. I don't know it very clearly. And that's why I want to understand it; for it's...
22
by: bitshadow | last post by:
using the following code, i was able to have my compiler seg fault on me when i gave the argument as anythng greater than 20,832,000bytes. In the case of the struct its 868 instances of said...
7
by: unified | last post by:
Ok, I'm working on a program that is supposed to compare each letter of a string that is put into a stack and a queue. It is supposed to tell whether or not a word is a palindrome or not. (a...
8
by: LedZep | last post by:
What up everyone, I have to write a program that uses a stack to determine whether a string is a palindrome (a string that is spelled identically backward and forward). The program has to...
7
by: DevNull | last post by:
Hello everyone, I decided to pick c++ back up after not really having used it much in 10 years. Just as a point of refference, there was no standard C++ last time I used regularly. Anyways...
5
by: playagain | last post by:
Please help me to build a list of examples of stack and queue in real life situation... Conditions: The object concerned must only one object. And the object must be tangible. Example: Queue...
87
by: CJ | last post by:
Hello: We know that C programs are often vulnerable to buffer overflows which overwrite the stack. But my question is: Why does C insist on storing local variables on the stack in the first...
5
AmberJain
by: AmberJain | last post by:
HELLO, The book (which I'm presently referring) of C programming says- "A stack is an example of a LIFO (Last In First Out) structure, as opposed to, for example, a queue, which is a FIFO (First In...
62
by: jt | last post by:
hello everyone.. int fun() { /* anything */ } int main(void) { fun(); }
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.