QUEUE in C


#include <stdio.h>
#define size 100

int queue[size];
int posisi;

push(int data){
   if(posisi==size){
      printf("antrian penuh....\n");
   }else{
      queue[posisi] = data;
      posisi++;
   }
}

pop(){
   int i = 0;
   printf("%d keluar.\n", queue[i]);
   for(i = 0; i<size-1; i++){
      queue[i]=queue[i+1];
   }
   queue[size-1]=0;
   posisi--;
}

cetak(){
   int i = 0;
   for(i=0; i<size; i++){
      printf("%d ", queue[i]);
   }
   printf("\n");
}

void menu(){
   printf("1. PUSH\n");
   printf("2. POP\n");
   printf("3. CETAK\n");
   printf("4. KELUAR\n");
}

main(){
   int a;
   int data;
   while(1){
      menu();
      printf("Pilihan anda: ");
      scanf("%d", &a);
      switch (a){
         case 1: {
              printf("data: ");
              scanf("%d", &data);
              push(data);
              break;
         }
         case 2: pop(); break;
         case 3: cetak(); break;
         case 4: exit(1);
         default: exit(1);
      }
   }
   getch();
   return 0;
}

About windupurnomo

I'm interested in programming. I am active with several programming such as Java, C #, C, JavaScript, HTML. I'm also develop desktop application (Java Swing), Mobile Application (Android), and Web programming (ASP MVC).
This entry was posted in C Language, Struktur Data and tagged , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s