Stack is a queue wich adopt a last-in first-out strategy.
If you would like to use an array to implemet a stack, you have to keep in mind that:
1] When you are inserting an element in the stack (push), you can write the element in the first available position of the array, making sure that the position is within the array dimension.
2] When you are removing an element (pop), you are extracting the last element...
User Profile
Collapse
-
typos
There are some syntax errors and some calls to non-existent functions.
You should check that all constant strings you would like to print with fprintf are enclosed in quotes:
fprintf(stderr, "This is an error );
fprintf(stderr, "This is correct");
and you should also check that all brackets are matched: whenever you open a bracket there must be the correponding closing...Leave a comment:
-
-
mastern2000,
this would probably do the trick:
Code:double Compound(double capital, double interest, int months) { if (months==1) return capital*(1+interest); else return (1+interest)*Compound(capital,interest, months--); }Leave a comment:
-
tedarr,
have you tried using
to get the rectangle ID in the error-reporting functions?Code:this->objID
Leave a comment:
-
What I would do is create three classes: one class for the book object, one for the customer object, and one class for the library, that is a collection of both books and one of customers, implemented as lists.
Henceforth, my headers would look something like:
...Code:class Book{ private: string Title; string Author; int ISSBN; public: Book *pnext; Book();Leave a comment:
-
The first line creates a new object filebuf by mean of its constructor "filebuf()" , and address it using a pointer to filebuf called "buf".
Then a file name "log000000. txt" is initialized.
The cyvle, checks if a file named "log000000. txt" exist, using the filebuf method open(). If it exist, it changes the file name to "log000001.txt" , and checks it existence, and son on incrementing the...Leave a comment:
-
Thank you all, very much,
that shed some light.
So, for what I understand, gcc uses C99 standard even when compiling plain C++, even if standard C++ does not support some of its features....Leave a comment:
-
For what I knew, static allocation, as "double vect[dim];", requires the compiler to know the dimension of the required memory at compile time. In my piece of
code this is not the case.
Am I right?
To make things worse, the same code is not compiled by Visual C++, since the value of "dim" is not known......Leave a comment:
-
gcc: static allocation of array with variable size
Hi everyone.
Is anybody able to explain to me why gcc will compile without the slightest warning the following code?
Code:#include <iostream> int main() { int dim; cin>> dim; double array[dim]; // operations on the array return 0; }
No activity results to display
Show More
Leave a comment: