#include <iostream.h>
#include <stdlib.h>
struct stash
{
struct link
{
int data;
link* next;
void initialize(int Data,link* Next);
}* head;
void* pop();
void* peek();
void initialize();
void push(int data);
void cleanup();
void print();
};
void stash::print()
{
cout<<"hello world!"<<endl;
}
void stash::link::initialize(int Data,link* Next)
{
data=Data;
next=Next;
}
void* stash::pop()
{
if(head!=0)
{
link* cur=head;
head=cur->next;
cout<<"stash::pop() is used!"<<endl;
cout<<"the pop data is:"<<cur->data<<endl;
free(cur);
// free(cur->data);
free(cur->next);
}
else
{
cout<<"there is no data in stash!"<<endl;
}
}
void* stash::peek()
{
}
void stash::initialize()
{
head=0;
}
void stash::push(int data)
{
link* curent=(link*)malloc(sizeof(link));
curent->data=data;
curent->next=head;
head=curent;
}
void stash::cleanup()
{
link* cur;
while(head)
{
cur=head;
head=head->next;
free(cur);
}
cout<<"stash is empty!"<<endl;
}
int main()
{
//cout<<"hello world!"<<endl;
stash sh;
sh.print();
cout<<sizeof(stash)<<endl;
sh.initialize();
for(int i=0;i<10;i++)
{
sh.push(i);
}
for(int i=0;i<10;i++)
{
sh.pop();
}
sh.cleanup();
sh.pop();
return 0;
}