Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- struct no
- {
- int info;
- struct no *next;
- };
- typedef no* noptr;
- void pushc (noptr &pilha, int x)
- {
- noptr p;
- p = new no;
- p->info = x;
- if (pilha == NULL) // ´e o primeiro n´o
- pilha = p;
- else
- p->next = pilha->next; // j´a existem outros n´os
- pilha->next = p;
- }
- int popc (noptr &pilha, int &x)
- {
- noptr p;
- if (pilha == NULL) // a pilha j´a est´a vazia
- return -1;
- else // removendo n´o ininicial
- {
- p = pilha->next;
- x = p->info;
- if (p == pilha) // somente um n´o na pilha
- pilha = NULL;
- else // j´a existem outros n´os na pilha
- pilha->next = p->next;
- delete p;
- return 0;
- }
- }
- void exibec(noptr &lista)
- {
- noptr t = NULL;
- noptr w = NULL;
- pushc(w,lista->info);
- for(t = lista->next; t != lista; t = t->next)
- {
- pushc(w,t->info);
- }
- cout << w->info << " ";
- for(t = w->next; t != w; t = t->next)
- {
- cout << t->info << " ";
- }
- }
- int main()
- {
- noptr pilha = NULL;
- int val;//valor do nó
- cin >> val;
- while(val != 0)
- {
- pushc(pilha, val);
- cin >> val;
- }
- exibec(pilha);
- while(popc(pilha,val)==-1);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement