Seiha Blog |
Posted: 01 Aug 2012 12:51 AM PDT Output : Teori Linked List 1 Teori Linked List 2 #include <stdio.h> struct _simpul { char kode; int angka; struct _simpul *next; }; typedef struct _simpul simpul; /*Deklarasi fungsi pencarian pada linked list*/ simpul *Cari (simpul *List, char C) { simpul *P = List; while (P-> kode !=C) { P = P-> next; if (!P) break; } return P; } int main (void){ #define n 20 simpul k [n], *head, *p; char Kode [n] = "dfhajcbgieDFHAJCBGIE"; int j; char C; for (j = 0; j < n; j++) { k[j]. kode = Kode[j]; k[j]. angka = j+1; }; head = &k[0]; for (j = 0; j < n-1; j++) k[j]. next = &k[j+1]; k[j]. next = NULL; /*Menampilkan isi List*/ printf ("Isi List : "); p = head; do { printf ("%c",p ->kode); p = p ->next; } while (p !=NULL); printf ("\n"); do { printf ("Masukkan karakter yang dicari (<ENTER> = selesai):"); C = getchar (); p = Cari (head, C); if (p) printf ("Data ditemukan pada simpul ke - %d \n", p -> angka); else printf ("Data tidak ada! \n"); while (getchar () !='\n') continue; } while (C != '\n'); return 0; } |
You are subscribed to email updates from Wammy's Blog To stop receiving these emails, you may unsubscribe now. | Email delivery powered by Google |
Google Inc., 20 West Kinzie, Chicago IL USA 60610 |