#include "iostream"
using namespace std;
class linknode
{
public:
linknode *next;
int value;
linknode();
};
linknode::linknode()
{
next = NULL;
value = -1;
}
class linklist
{
public:
linknode *head;
int count;
};
class Stack
{
public:
linklist list;
Stack();
void push(linknode *node);
void pop(linknode *node);
void show();
bool exsit(int value);
void clear();
};
Stack::Stack()
{
list.count =0;
list.head = new linknode;
}
void Stack::push(linknode *node)
{
linknode *temp = list.head;
if (!temp->next)
{
temp->next = node;
list.count ++;
}
else
{
node->next =temp->next;
list.head->next = node;
list.count ++;
}
cout <<"node value"<<node->value<<endl;
}
void Stack::pop(linknode *node)
{
linknode *temp =list.head;
linknode *prenode;
while(temp->next)
{
prenode = temp;
temp = temp->next;
if (node->value == temp->value)
{
linknode *nextnode = temp->next;
prenode->next = nextnode;
cout<<"DELETE VALUE "<<node->value<<endl;
delete temp;
this->list.count --;
return;
}
}
cout<<"NOT FOUND"<<endl;
return;
}
void Stack::show()
{
linknode *temp =list.head;
while(temp->next)
{
temp = temp->next;
cout<<temp->value;
}
return;
}
bool Stack::exsit(int value)
{
linknode *temp =list.head;
bool flag =false;
while(temp->next)
{
temp =temp->next;
if (temp->value == value)
{
cout<<value<<" EXIST"<<endl;
flag = true;
}
}
return flag;
}
void Stack::clear()
{
linknode *temp =list.head->next;
linknode *current;
while(temp)
{
current = temp;
temp = temp->next;
cout<<"value "<<current->value<<" DELETED "<<endl;
delete current;
list.count --;
}
}
int main()
{
Stack s;
for (int i=0;i<10;i++)
{
linknode *node = new linknode;
node->value = i;
s.push(node);
}
linknode *unused = new linknode;
unused->value = 0;
s.pop(unused);
s.show();
if (s.exsit(5))
{
cout<<"FOUND"<<endl;
}
s.clear();
return 0;
}