Daftar

[TANYA]yg bisa bhs C "single linked list" tolongin ane dong?


Programming & Web Coding, web, aplikasi, dan karier developer.

Balas
 
Alat Thread
Guesuper Guesuper sedang offline
#1
Ceriwiser Tanggal Bergabung: Nov 2011 Post: 408 Rep Power: 16 Guesuper mempunyai hidup yang Normal
Default [TANYA]yg bisa bhs C "single linked list" tolongin ane dong?
nih gan=



//STACK USING SINGLE LINKED LIST

#include

#include



struct data

{

int angka;

struct data *next;

}*head,*curr,*tail;



void push(int angka)

{

curr=(struct data*)malloc(sizeof(struct data));

curr->angka=angka;



if(head==NULL)

{

head=tail=curr;

}

else

{

tail->next=curr;

tail=curr;

}

tail->next=NULL;



printf("Push berhasil.");

getchar();

}



void pop()

{

curr=head;

if(head==NULL)

{

printf("Data masih kosong");

}

else

{

if(head==tail)

{

free(head);

head=NULL;

}

else

{

head=head->next;

free(curr);

}

}

}



void cetak()

{

curr=head;



while(curr)

{

printf("%d",curr->angka);

curr=curr->next;

}

}



void main()

{

int choose,angka;



do{

system("cls");

cetak();



printf("\n\nMenu:\n");

printf("1. Push.\n");

printf("2. Pop.\n");

printf("3. Exit.\n");

printf("Pilih(1-3): ");

do{

scanf("%d",&choose);

fflush(stdin);

}while(choose3);



switch (choose)

{

case 1:

printf("\nAngka berapa yang ingin dipush: ");

scanf("%d",&angka);

fflush(stdin);

push(angka);

break;

case 2:

pop();

break;

}

}while(choose!=3);



printf("\n\n\nTERIMAKASIH\n");

printf("%c%c%c%c%c%c%c%c%c%c%c",219,219,219,219,21 9,219,219,219,219,219);



getchar();

}



pertanyaan ane, kenapa yang ane bold harus ada? padahal kan udah di free, kenapa perlu di NULLin. kan datanya cuma satu.



(ini bukan tugas, sekedar ingin tau saja)

</div>
Balas


Aturan Posting
Kamu tidak boleh membuat thread baru
Kamu tidak boleh membalas
Kamu tidak boleh mengirim lampiran
Kamu tidak boleh mengedit post kamu

BB code Hidup
Smilie saat ini Hidup
Kode [IMG] adalah Hidup
Kode HTML adalah Mati


Terkait
Thread Pembuat Thread Forum Balasan Postingan Terakhir
para agan&quot; n yg bisa tolongin......?? filmhorror Misteri & Horor 0 22 Apr 2012 03:42 PM
yang bisa java Tolongin ane dong Permenkaret Programming & Web 0 20 Nov 2011 02:19 AM
CIRCULAR LINKED LIST in C++(tolongin gan) Braincode Programming & Web 0 11 Nov 2011 02:01 PM