Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- struct Node{
- int valor;
- struct Node *point;
- };
- typedef struct Node node;
- int menu(){
- int op;
- printf(" ______________Menu_____________\n");
- printf("| |\n");
- printf("|0- Sair |\n");
- printf("|1- Inserir |\n");
- printf("|2- Remover |\n");
- printf("|3- Mostrar |\n");
- printf("|_______________________________|\n");
- printf("\nInsira sua opcao: ");
- scanf("%d",&op);
- return op;
- }
- /*
- void push(node **top,int valor){
- node *temp = (node*) malloc(sizeof(node*));
- temp->point=*top;
- temp->valor=valor;
- *top=temp;
- }
- void mostrar(node **top) {
- node * temp = *top;
- while(temp != NULL) {
- printf("%d\n", temp->valor);
- temp = temp->point;
- }
- }
- int pop(node **top){
- int x;
- node *temp = *top;
- x=temp->valor;
- temp=temp->point;
- *top=temp;
- return x;
- }
- */
- void push(node *top,int valor){
- node *novo = (node*) malloc(sizeof(node*));
- node *aux = top->point;
- novo->valor=valor;
- novo->point=aux;
- top->point=novo;
- }
- int pop(node *top){
- node *temp = top;
- node *aux;
- aux=temp->point;
- temp=aux;
- int x;
- x=temp->valor;
- temp=temp->point;
- free(temp);
- return x;
- }
- void mostrar(node *top) {
- node * temp = top;
- node *aux;
- aux=temp->point;
- temp=aux;
- while(temp != NULL){
- printf("%d\n", temp->valor);
- temp = temp->point;
- }
- }
- int main(){
- node top;
- top.point=NULL;
- int valor,op;
- do{
- op=menu();
- switch(op){
- case 0: break;
- case 1:
- printf("Digite o valor a inserir: ");
- scanf ("%d",&valor);
- push(&top,valor);
- break;
- case 2:
- printf("%d\n",pop(&top));
- break;
- case 3:
- mostrar(&top);
- break;
- default:
- printf("Opcao invalida\n");
- break;
- }
- system("pause");
- system("cls");
- }while(op!=0);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement