Rabu, 29 Mei 2013

PROGRAM STACKED DENGAN FUNGSI DALAM BAHASA C


PROGRAM STACK DENGAN FUNGSI

#include <stdio.h>
//YOGI PRATAMA
void main()
{              int stack[100];
                int top=-1;
                intpilih, i;
                do{
                                printf("MENU\n");
                                printf("1. PUSH\n2. POP\n3. VIEW\n4. EXIT\n");
                                printf("Pilih = "); scanf("%d", &pilih);
                                switch(pilih){
                                                case 1://push
                                                                if (top > 100)
                                                                printf("Stack penuh!\n");
                                                                else{
                                                                printf("Data = "); scanf("%d", &stack[top+1]);
                                                                top++;
                                                system("cls");
                }
                break;
case 2://pop
                if (top < 0)                                                          
printf("Stack kosong!\n");                                                          
else{                                                     
printf("Data keluar = %d\n", stack[top]);
                top--;
                }
break;                                  
case 3://view
            {
if (top < 0)          
            {                                 
printf("Stack kosong!\n");          
                }                                             
else{                                                     
printf("Data keluar = %d\n", stack[top]);
                                                                for(i=top; i>=0; i--);
                                                                {
                                                                printf("%d", stack[i]);
            }
                                                                printf("\n");
            }
                                                                break;
            }
case 4:
printf("Exit…\n");
break;
                }
                }while (pilih!=4);
}

//YOGI PRATAMA

1 komentar:

  1. artikelnya bermanfaat kak, ini sya jga punya artikel tentang Stack (tumpukan) dalam Bahasa C, smoga dpt saling melengkapi

    Stack (tumpukan) dalam Bahasa C

    Kumpulan Materi Bahasa C, Lengkap dengan contoh program

    BalasHapus