Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <ctype.h>
- #define MAXSIZE 10
- int stack[MAXSIZE];
- int top;
- void main()
- {
- void push(int);
- int pop();
- int pil=1,i,num,j;
- clrscr();
- while(pil == 1)
- {
- clrscr();
- printf("MAIN MENU\n");
- printf("1. Tambah elemen stack\n");
- printf("2. Hapus elemen dari stack\n");
- printf("3. Tampilkan stack\n");
- printf("4. Keluar\n");
- printf("Pilih");
- scanf("%d",&pil);
- switch(pil)
- {
- case 1: printf("\nMasukkan data : ");
- scanf("%d",&num);
- push(num);
- break;
- case 2: pop();
- printf("\nStack telah di hapus");
- break;
- case 3: printf("\nStack %d \n", stack[top]);
- printf("\nIsi Stack selengkapnya:\n");
- while(top!=NULL){
- printf("%d \n", stack[top--]);
- }
- break;
- case 4: exit(0);
- break;
- default: printf("Salah pilih");
- }
- printf("\nUlang??\n( 1 untuk ulang, angka lain untuk keluar) ");
- scanf("%d", &pil);
- }
- }
- void push(int y)
- {
- if(top>MAXSIZE)
- {
- printf(" STACK FULL");
- return;
- }
- else
- {
- top++;
- stack[top]=y;
- }
- }
- int pop()
- {
- int a;
- if(top<=0)
- {
- printf("STACK EMPTY");
- return 0;
- }
- else
- {
- a=stack[top];
- top--;
- }
- return(a);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement