-
-
Save ganobrega/5bb15ae504f9b757cad80cb1d664ac10 to your computer and use it in GitHub Desktop.
Stack Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Stack using array | |
//Author: Milon | |
//Update: Gabriel | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#define MAX_ITENS 4 | |
void push(char *a); | |
void pop(); | |
void display(); | |
int top=0; | |
int stack[MAX_ITENS]; | |
void main(){ | |
push("Gabriel"); | |
push("Maria"); | |
push("Fernando"); | |
pop(); | |
push("José"); | |
display(); | |
} | |
void push(char *nome){ | |
if(top==MAX_ITENS){ | |
printf("\nA Pilha está sobrecarregada."); | |
return; | |
} | |
stack[top]=nome; | |
top=top+1; | |
} | |
void pop(){ | |
if(top==0){ | |
printf("\nA Pilha está vazia."); | |
//getch(); | |
return; | |
} | |
stack[top] = ""; | |
top=top-1; | |
} | |
void display(){ | |
if(top==0){ | |
printf("\nA Pilha está vazia."); | |
return; | |
} | |
printf("\n--------------------------------------------------------------"); | |
for(int i=0;i < top;i++){ | |
printf("\n%d --> %s",i, stack[i]); | |
} | |
printf("\n--------------------------------------------------------------"); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment