#include<stdio.h>
#include<conio.h>
#define MAX_STACK 10
typedef struct STACK {
int top;
char data[10][10];
};
STACK tumpuk;
void inisialisasi(){
tumpuk.top = -1;}
int IsFull(){
if(tumpuk.top == MAX_STACK-1) return 1; else return 0;}
int IsEmpty(){
if(tumpuk.top == -1) return 1; else return 0;}
void Push(char d[10]){
tumpuk.top++;
strcpy(tumpuk.data[tumpuk.top],d);}
void Pop(){
printf(”******************************\n”);
printf(”DATA YANG TERAMBIL ADALAH = %s\n”,tumpuk.data[tumpuk.top]);
tumpuk.top–;
printf(”******************************\n”);
}
void Clear(){
tumpuk.top=-1;}
void TampilStack(){
for(int i=tumpuk.top;i>=0;i–){
printf(”******************************\n”);
printf(”DATA YANG SEKARANG ADALAH : %s\n”,tumpuk.data[i]);
}}
int main(){
int pil;
inisialisasi();
char dt[10];
do{
printf(”%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n”);
printf(”==> Created by :\n”);
printf(” ==> Nama : Evelyn\n”);
printf(” ==> Operating Sytem : Ubuntu Linux Gusty Gibbon 7.10\n”);
printf(”|===========================================|\n”);
printf(”|=============== |MENU UTAMA| ==============|\n”);
printf(”|===========================================|\n”);
printf(”1. push (Untuk Menambah Stack)\n”);
printf(”2. pop (Untuk Mengambil Stack Teratas)\n”);
printf(”3. print (Untuk Menampilkan Seluruh Data Yang Ada Di Dalam Stack)\n”$
printf(”4. clear (Untuk Mengosongkan Stack)\n”);
printf(”5. exit (keluar dari program)\n\n”);
printf(”Masukkan Pilihan Anda : “);scanf(”%d”,&pil);
switch(pil){
case 1: if(IsFull() != 1){
printf(”******************************\n”);
printf(”DATA YANG DI INPUT = “);scanf(”%s”,dt);
Push(dt);
printf(”******************************\n”);
}
else printf(”\n Data Sudah penuh!\n”);
printf(”\n”);
break;
case 2: if(IsEmpty() != 1)
Pop();
else
printf(”\nDATA MASIH KOSONG!\n”);
printf(”\n”);
break;
case 3: if(IsEmpty() != 1)
TampilStack();
else
printf(”\nDATA => MASIH KOSONG !\n”);
printf(”\n”);
break;
case 4: Clear(); printf(”\nDATA ===> SUDAH KOSONG !\n”);
printf(”\n”);
break;
}
}while(pil != 5);
getch();
clrscr();
}
No comments:
Post a Comment