Homework Solution 2: stack.cc
// Accessor function to return the number of items on the stack
int stack::size()
{
return count_items(data_list);
}
// Push a value onto the stack by prepending an element to the
// linked list
void stack::push(int i)
{
item *new_top;
new_top = new item;
new_top->data = i;
new_top->next = data_list;
data_list = new_top;
}
Previous slide
Next slide
Back to first slide
View graphic version