0

Pengertian, Macam - macam, dan Penggunaan Linked List dalam C++

Posted by jujur on 5:34 AM

Pengertian, Macam - macam, dan Penggunaan Linked List dalam C++

Linked list adalah sekumpulan elemen bertipe sama, yang mempunyai keterurutan tertentu, yang setiap elemennya terdiri dari dua bagian Linked list juga merupakan suatu cara untuk menyimpan data dengan struktur sehingga dapat secara otomatis menciptakan suatu tempat baru untuk menyimpan data yangdiperlukan. Struktur ini lebih dinamis karena banyaknya elemen dengan mudah ditambah atau dikurangi, berbeda dengan array yang ukurannya tetap. berikut gambaran kecil mengenai linked list.



Didalam Linked List terdapat beberapa bagian lagi

       1. Linked List Circular


Double Linked List 

       Pengertian secara umumnya DLLC itu Linked list yang menggunakan pointer, dimana setiap node memiliki 3 field, yaitu:
1 field pointer yang menunjuk pointer berikutnya "next",
1 field menunjuk pointer sebelumnya " prev ", 
1 field yang berisi data untuk node tersebut .

Double Linked List Circular pointer next dan prev nya menunjuk kedirinya sendiri secara circular. Bentuk Node DLLC















#include #include typedef struct{ char kode[12], artis[20], jenis_musik[40];char judul_lagu[30];}data_musik;data_musik music, tmpmusic;void inputData();void bukaData();void editData();void cariData();void hapusData();int main(int argc, char *argv[]){ int menuPilihan; while(menuPilihan !=0){                      system("CLS");    do{        printf("\n");        printf("=========================================\n");        printf("|        Data Musik          |\n");     printf("=========================================\n");        printf("|                                       |\n");        printf("|      1. Masukan Data                  |\n");     printf("|      2. Tampil Data                   |\n");     printf("|      3. Search                        |\n");     printf("|      4. Edit Data                     |\n");     printf("|      5. Hapus Data                    |\n");     printf("|      0. Exit                          |\n");        printf("=========================================\n");        printf("Masukan Pilihan [0..5] : ");scanf("%d",&menuPilihan);  system("CLS"); }while(menuPilihan < 0 || menuPilihan > 5);   switch(menuPilihan){  case 1:inputData();break;  case 2:bukaData();break;  case 3:cariData();break;  case 4:editData();break;  case 5:hapusData();break; }system("PAUSE");    }  return 0;}void inputData(){     system("CLS");     FILE *pfiledata;     pfiledata=fopen("data.txt","ab");     char kode[12],artis[20],jenis_musik[100];     int i=5,ketemu=0;     printf("==========================================\n");     printf("|        Input Nama Artis             |\n");     printf("==========================================\n");     printf(" kode musik            : ");fflush(stdin);gets(music.kode);     printf(" Nama Artis            : ");fflush(stdin);gets(music.artis);     printf(" Jenis Musik           : ");fflush(stdin);gets(music.jenis_musik);     printf("Judul lagu             : ");fflush(stdin);gets(music.judul_lagu);     printf("==========================================\n");     fwrite(&music,sizeof(music),1,pfiledata);     fclose(pfiledata);}void cariData(){     system("CLS");     FILE *pfiledata;     pfiledata=fopen("data.txt","rb");     char x[20];     int ketemu;     char jawab;     printf("==================================\n");     printf("|    Masukan Berdasarkan Nama    |\n");     printf("|                                |\n");     printf("|    Masukan Nama Artis :\n");     printf("==================================\n");     fflush(stdin);gets(x);     system("CLS");     fread(&music,sizeof(music),1,pfiledata);     ketemu=0;     do{     if(strcmpi(music.artis,x)==0)              {                printf("|          Data Data Musik       |\n");                printf("===========================================\n");                printf("    kode          : %s     \n",music.kode);                printf("    Nama Artis      : %s     \n",x);                printf("    Jenis Musik     : %s   \n",music.jenis_musik);                printf("    Judul Lagu      : %s  \n \n",music.judul_lagu);                printf("===========================================\n");   ketemu=1; }                fread(&music,sizeof(music),1,pfiledata);                }while(!feof(pfiledata));                if(!ketemu)              {                  printf("DATA TIDAK DITEMUKAN\n\n");     }     fclose(pfiledata);}void editData(){  system("CLS");  FILE *pfiledata, *pfiletemp;  pfiledata=fopen("data.txt","rb");  pfiletemp=fopen("datatemp.txt","wb");  char x[10];  int ketemu;  char jawab;  printf("=====================================================\n");  printf("|                                                   |\n");  printf("|       Cari Data Berdasarkan kode Lapangan         |\n");  printf("|              Masukan kode                         |\n");  printf("|                                                   |\n");  printf("=====================================================\n");  fflush(stdin);gets(x);  system("CLS");  fread(&music,sizeof(music),1,pfiledata);  ketemu = 0;  jawab = 'Y';     do     {        if(strcmpi(music.kode,x)==0)          {            printf("===========================================\n");            printf("|           EDIT DATA Data Musik |\n");            printf("===========================================\n");            printf("    kode            : %s                  \n",x);            printf("    Nama Artis      : %s                   \n",music.artis);            printf("    Jenis Musik     : %s                   \n",music.jenis_musik);            printf("    Judul Lagu      : %s                    \n",music.judul_lagu);            printf("===========================================\n");            printf("|       APAKAH KAMU YAKIN  ? [Y/T] :        |\n");            printf("===========================================\n");            scanf("%c",&jawab);                  if(toupper(jawab)=='Y')                    {                       system("CLS");                       printf(" kode                 : ");fflush(stdin);gets(music.kode);                       printf(" Nama Artis          : ");fflush(stdin);gets(music.artis);                       printf(" Jenis Musik         : ");fflush(stdin);gets(music.jenis_musik);                       printf(" Judul Lagu          : ");fflush(stdin);gets(music.judul_lagu);                       fwrite(&music,sizeof(music),1,pfiletemp);                       ketemu=1;                    }                  else                       fwrite(&music,sizeof(music),1,pfiletemp);                }      else                   {                      fwrite(&music,sizeof(music),1,pfiletemp);                   }       fread(&music,sizeof(music),1,pfiledata);     }while(!feof(pfiledata));     if(!ketemu)              {                  printf("     DATA TIDAK 'DI UBAH' \n\n");     }fclose(pfiletemp);fclose(pfiledata);remove("data.txt");rename("datatemp.txt","data.txt");}void hapusData(){     system("CLS");     FILE *pfiletemp, *pfiledata;     pfiledata=fopen("data.txt","rb");     pfiletemp=fopen("datatemp.txt","wb");     char x[10];     int ketemu;     char jawab;     printf(" ==============================================\n");     printf("                                              \n");     printf("       Hapus Data Berdasarkan kode Musik           \n");     printf("          Masukan kode Musik                      \n");     printf("                                              \n");     printf(" ==============================================\n");     fflush(stdin);gets(x);     system("CLS");     fread(&music,sizeof(music),1,pfiledata);     ketemu = 0;     jawab = 'Y';     do     {              if(strcmpi(music.kode,x)==0)              {                printf("===========================================\n");                printf("                DATA Data Musik       \n");                printf("===========================================\n");                printf("     kode           : %-10s                   \n",x);                printf("     Nama Artis       : %-10s                   \n",music.artis);                printf("     Jenis Musik      : %-10s                   \n",music.jenis_musik);                printf("     Judul Lagu       : %-10s                    \n",music.judul_lagu);                printf("===========================================\n");                printf("DATA AKAN DI HAPUS, ARE YOU SURE ? [Y/T] :   ");                scanf("%c",&jawab);                  if(toupper(jawab)=='Y')                    {                            printf("DATA DIHAPUS\n");                            ketemu=1;                    }                  else                            fwrite(&music,sizeof(music),1,pfiletemp);                }      else                   {                   fwrite(&music,sizeof(music),1,pfiletemp);                   }       fread(&music,sizeof(music),1,pfiledata);     }while(!feof(pfiledata));     if(!ketemu)              {                  printf("DATA TIDAK 'DI HAPUS'\n\n");     }fclose(pfiletemp);fclose(pfiledata);        remove("data.txt");        rename("datatemp.txt","data.txt");}void bukaData(){     system("CLS");     FILE *pfiledata;     pfiledata=fopen("data.txt","rb");     typedef struct             {char kode[12], artis[20], jenis_musik[40], judul_lagu[30];                   }data_musik;     data_musik music;     int i=5,j=1;    printf("===========================================\n");    printf ("|          Data Musik                  |\n");    printf ("===========================================\n"); rewind(pfiledata); while(fread(&music,sizeof(music),1,pfiledata)){        printf("%i.",j);        printf(" kode         : %s\n",music.kode);        printf(" Nama Artis     : %s\n",music.artis);        printf(" Jenis Musik    : %s\n",music.jenis_musik);        printf(" Judul Lagu     : %s \n \n",music.judul_lagu);        i=i+5;        j++; } fclose(pfiledata);     }

Untuk Source Code  dibawah

0 Comments

Copyright Jujur Soaloon Sitangang Lipan All rights reserved. Theme by Sitanggang. | Bloggerized by Soalparna.