Can anyone direct me where to go for doing stacks in C++. I have to make a program using stacks but can you initialize a stack with given values? If so can you give an example?

en……maybe STL template lib may fulfill you need ;)

but i always write a simple data-struct for the program...

This would be an example of a stack of integers using a list ...

// example of a stack (Last In First Out = LIFO) using a list
// compares to a stack of dinner plates
// Dev-C++


using namespace std;

int main()
  list iL;
  int k;

  // load the stack with numbers 0 to 9, last number entered would be on top
  for(k = 0; k < 10; k++)

  // now unload the stack and display
  cout << "Unloading the stack in order:\n";
  for(k = 0; k < 10; k++)
    // read the top element of the list
    cout << iL.front() << endl;
    // now pop it (removes top element)

  cin.get();  // wait
  return 0;

Edited 4 Years Ago by vegaseat: replaced old code tags

This question has already been answered. Start a new discussion instead.