Function that checks to see if stack is Full apparently non-existent now. What's up with that mess!?

+2 Melissa Ries · April 11, 2015
Okay so I am trying to do my homework where I have to input a file and output a segment of code using stacks. My book specifies that I use the "isFullStack" member function...only it does not work :angry:

I have tried in both CodeBlocks and VisualStudio and both read errors. The compiler doesn't recognize it no matter what I do. I have googled it and can't find anything. According to cplusplus the member function doesn't exist.

So I guess my textbook is no longer up to date???

Is there another way that I can check to see if the stack is full or am I just shit out of luck?


    

Post a Reply

Replies

Oldest  Newest  Rating
0 Melissa Ries · April 11, 2015
The object is an input file. I am trying to run the program without checking to see if the stack is full by checking to see if its empty but I think that is messing up the entire output. I will try to paste my code. The code text editor isn't working right. I may have to copy it manually. Just bare with me if its wacky. 

#include <iostream>
#include <fstream>
#include <stack>
using namespace std;

int main()
{
    stack<int> stackType;
    int x;


    ifstream newFile ("bacon.txt");

    if (!newFile){
        cout << "The file does not "
            << "exist. FAIL! You Suck!!!" << endl;
            return 1;
    }

    stackType.push(5);

    cin >> x;

    while (x != -999){
        if(x % 2 == 0){
            if (!stackType.isFullStack()) //supposed to check the stack to see if its NOT full 
                stackType.push(x);
        }
        else
            cout << "x = " << x << endl;
        cin >> x;
    }
    cout << "Stack elements: ";

    while (!stackType.empty()){
        cout << " " << stackType.top();
        stackType.pop();
    }
    cout << endl;

    newFile.close();
}
0 Melissa Ries · April 11, 2015
Thanks for the help. I think my text book may be outdated. I have to use the information given to me to show a specific output. I will find some way to work it. For now I'm going to bed and will sleep on it. Thanks again.
+1 Tatrasiel R · April 17, 2015
Firstly, Thanks for asking a good question!

Is this question from this book?
https://books.google.com/books?id=reQKAAAAQBAJ&pg=PA1126&lpg=PA1126&dq=isFullStack+c%2B%2B&source=bl&ots=OLhuPMWKVa&sig=LFRtIptcOA4uvc-g2xBvYyvtB9o&hl=en&sa=X&ei=2LEwVczNGJXdoAT7jIH4Bw&ved=0CDcQ6AEwAw#v=onepage&q=isFullStack%20c%2B%2B&f=false


Also, I think the type is bool because we're looking for 1 or 0 return. 

bool StackType<Type>::IsStackFull();


Someone can correct me, but I would think excepting and better memory practices would be better here.  If you don't except, at least the OS will do it for you, resulting in terminating the process with an exception code.
If you run out of stack space it's called a stackoverflow and it typically a problem that many programmers make. 
Also, I can see that you're trying to do assembly in C++ They're better ways to do this and I have an assembly course in case you want to learn about the stack. Example:
__asm
{
   mov eax, ebx
}

Here is another link talking about this using AT&T syntax

http://stackoverflow.com/questions/5131568/using-inline-assembly-in-c-c



 Not to superseded anyone, but if you're getting out of memory AKA OOMS then you should probably review your code strictly . Visual studio 2013  has an analysis that can help with this. Also (My preferred method.) opening a debugger can help you find these problems.
Memory problems are always the worst, next to security problems!
Let me know if you need anything more on this. I can try to rework your code to have it work, but I think the exercise is rather poor for what you'll get in return.
0 Melissa Ries · April 17, 2015
Thanks Tatrasiel. I am in Data Structures C++. The code I wrote was specific to the exercise in my book and I had to output an exact outcome. 

No that isn't the book. The Book I'm using is Data Structures Using C++ 2nd edition by D.S. Malik.

I figured that the isFullStack() function is no longer being used bc the stack is never full. I guess that function is pretty useless bc the bool will always give the same false output. 

I went ahead and figured out the output by problem solving in my head. I got it right, and the teacher didn't mark off, so I guess I understood it. lol. Btw the output was 5. 

Thanks again. I will def let you know if I need more help. I would also love to learn more about the stack. Thanks
0 Tatrasiel R · April 17, 2015
Let's say the key for many vulnerabilities are from overwriting values in the stack. 

I'd say that Vivek explains the stack best in this video

https://www.youtube.com/watch?v=K0g-twyhmQ4

I have an assembly course 
https://www.youtube.com/watch?v=mYCyMaGk8E0&list=PL_joX3jb1YBMTqH_2QTrpqVxHi-EhokHG

I am still actively adding videos to this series and probably will continue to more advanced topics.


EDIT:
I didn't see your message until now. I was thrown off by the 
stack.push and such which would be just like using the stack.
  • 1

C++

107,122 followers
About

Used in many types of software including music players, video games, and many large scale applications.

Links
Moderators
Bucky Roberts Administrator