linked list

Contoh Linked List

Contoh Linked List

hitung jumlah simpul :

Q = FIRST;
Jum = 1;
while (Q != LAST)
  { Q = Q->LINK;
    Jum = Jum + 1;
  }
printf("%i", JUM);

atau

Q = FIRST;
Jum = 1;
while (Q->LINK != NULL)
  { Q = Q->LINK;
    Jum = Jum + 1;
  }
printf("%i", JUM);

atau

Q = FIRST;
Jum = 0;
while (Q != NULL)
  {  Jum = Jum + 1;
     Q = Q->LINK;
  }
printf("%i", JUM);

membuat sebuah simpul yang ditunjuk pointer p :

scanf ("%i", &x);
p = (simpul*)malloc(sizeof(simpul));
p->info = x;


menjadikan sebuah simpul (p) menjadi simpul awal :

first = p;
last = p;
p->link = null;

insert kanan :

last->link = p;
last = p;
p->link = null;

insert kiri :

p->info = x;
p->link = first;
first = p;

insert tengah :

// dengan asumsi pointer q sudah ada di posisi insert tengah
p->link = q->link
q->link = p;

delete kiri :

q = first;
first = q->link;
free(q);

atau

q = first->link;
free(first);
first(q);

delete kanan :

free(last);
last = q;
last->link = null;

atau

last = q;
free(last->link);
last->link = null;

delete tengah :

r = q->link->link;
free(q->link);
q->link = r;

atau

// dengan asumsi pointer q sudah ada di posisi delete tengah
r = q->link;
q->link = r->link;
free(r);

arahkan pointer agar menunjuk simpul n :

Q = FIRST;
for( I=1; I<=n; I++) {
   Q = Q->LINK;
}

arahkan pointer agar menunjuk 2 simpul dari kanan :

Q = FIRST;
while(Q->LINK!=LAST) {
   Q = Q->LINK;
}

Bookmarks:
  • Facebook
  • Google Bookmarks
  • Digg
  • LinkedIn
  • Twitter

Related posts:

  1. double ended queue ciri2 double ended queue : kosong : L = R...
  2. penyimpanan data untuk database berorientasi object Sistem penyimpanan untuk database berorientasi object berbeda dengan sistem penyimpanan...
  3. double stack ciri2 double stack : stack 1 kosong : top1 =...
  4. single stack ciri2 single stack : kosong : top = -1 penuh...
  5. circular queue ciri2 circular queue : kosong : counter = 0 penuh...

Related posts brought to you by Yet Another Related Posts Plugin.

You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre user="" computer="" escaped="">