Uploaded by Nurgül Aykaş

stack

advertisement
STACK LİSTE IMPLEMENT
#include<iostream>
using namespace std;
struct node{
void main(){
node *root;
root = new node;
root->x = 1;
root->next = NULL;
int x;
node *next;
root=push(root, 2);
root = push(root, 3);
root = push(root, 4);
root = push(root, 5);
root = push(root, 6);
};
node *push(node *r, int deger){
if (r == NULL)
{
r = new node;
r->x=deger;
r->next = NULL;
}
else
{
node *tmp;
tmp = new node;
tmp->x = deger;
tmp->next = r;
r = tmp;
}
return r;
}
node *pop(node *r){
if (r == NULL)
cout << "stack bos";
else
{
node *tmp;
tmp = r;
r = r->next;
tmp->next = NULL;
delete[] tmp;
}
return r;
}
void yaz(node *r){
while (r!=NULL)
{
cout << r->x << endl;
r = r->next;
}
}
yaz(root);
system("pause");
root = pop(root);
root = pop(root);
yaz(root);
system("pause");
}
Download