Membuat Circular Single Linked List

Berikut adalah source code C untuk sebuah circular single linked list

 #include <stdio.h>  
 #include <stdlib.h>  
 void insert_first(int);  
 void insert_middle(int);  
 void insert_last(int);  
 void delete_first();  
 void delete_middle();  
 void delete_last();  
 typedef struct node{  
      int value;  
      struct nd *link;  
 } data;  
 data *first = NULL;  
 data *last = NULL;  
 int n=0;  
 int main()  
 {  
      int isi;  
      char command [100];  
      printf("Tulis command \n");  
      printf(">> Insert First\t > in_f\n");  
      printf(">> Insert Middle\t > in_m\n");  
      printf(">> Insert Last\t > in_l\n");  
      printf(">> Delete First\t > del_f\n");  
      printf(">> Delete Middle\t > del_m\n");  
      printf(">> Delete Last\t > del_l\n");  
      printf(">> Show the Linked List\t > show\n");  
      printf("\nMasukkan comamand : ");  
      scanf("%s", command);  
      while (strcmp(command, "exit") != 0)  
      {  
           if (strcmp(command, "in_f") == 0)  
           {  
                scanf ("%d", &isi);  
                insert_first (isi);  
           }  
           else if (strcmp(command, "in_m") == 0)  
           {  
                scanf ("%d", &isi);  
                insert_middle (isi);  
           }  
           else if (strcmp(command, "in_l") == 0)  
           {  
                scanf ("%d", &isi);  
                insert_last (isi);  
           }  
           else if (strcmp(command, "del_f") == 0)  
           {  
                delete_first();  
           }  
           else if (strcmp(command, "del_m") == 0)  
           {  
                delete_middle();  
           }  
           else if (strcmp(command, "del_l") == 0)  
           {  
                delete_last();  
           }  
           else if (strcmp(command, "show") == 0)  
           {  
                print_linked();  
           }  
           scanf("%s", command);  
      }  
      printf("%SELESAI\n");  
      return 0;  
 }  
 void insert_first (int nilai)  
 {  
      data *temp;  
      temp = (data*)malloc(sizeof(data));  
      temp->value = nilai;  
      if (first == NULL)  
      {  
           temp->link = NULL;  
           first = temp;  
           last = temp;  
      }  
      else   
      {  
           temp->link =   
      }  
 }  

Tidak ada komentar:

Posting Komentar