Skip to content

Latest commit

 

History

History
69 lines (55 loc) · 985 Bytes

File metadata and controls

69 lines (55 loc) · 985 Bytes

Mini Tutorial for the Stack class

stack_list<T> -- creates a stack implemented with a list.

splay tree contains: - push - top - pop - clear - size

push:

#include <stack_list.h>

stack_list<int> s;
s.push(10);
s.push(5);
s.push(4);
s.push(13);
// now the stack contains {10,5,4,13}

top:

#include <stack_list.h>

stack_list<int> s;
s.push(10);
s.push(5);
s.push(4);
s.push(13);

// this should return 13
std::cout << s.top() << '\n';

pop:

#include <stack_list.h>

stack_list<int> s;
s.push(10);
s.push(5);
s.push(4);
s.push(13);

// removes the top, in this case, 13
s.pop();

//this should return 4
std::cout << s.top() << '\n';

iterator:

#include <stack_list.h>

stack_list<int> s;
s.push(10);
s.push(5);
s.push(4);
s.push(13);

for(auto it = s.begin(); it != s.end(); it++){
    // *(it) returns the value of each node starting from the top
    std::cout << *(it) << '\n';
}