Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- struct no
- {
- int info;
- no *esq, *dir;
- };
- typedef no* noptr;
- void criaLista(noptr &lista, int x)
- {
- lista = new no;
- if(lista == NULL)
- {
- lista->esq = NULL;
- lista->dir = NULL;
- lista->info = x;
- }
- }
- int inseredir(noptr &p, int x)
- {
- if(p == NULL)
- {
- return 1;
- }
- else
- {
- noptr q = new no;
- q->info = x;
- noptr d = p->dir;
- p->dir = q;
- q->esq = p;
- q->dir = d;
- return 0;
- }
- }
- int main()
- {
- noptr lista = NULL;
- noptr cursor = NULL;
- int val;
- int move;
- cin >> val;
- while(val != 0)
- {
- if(lista == NULL)
- {
- criaLista(lista, val);
- }
- else
- {
- inseredir(lista, val);
- }
- cin >> val;
- }
- cursor = lista;
- cin >> move;
- while(move != -1)
- {
- if(move == 1)
- {
- if(cursor->dir != NULL)
- cursor = cursor->dir;
- }
- if(move == 0)
- {
- if(cursor->esq != NULL)
- cursor = cursor->esq;
- }
- val = cursor->info;
- cin >> move;
- }
- cout << cursor->info;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement