Tugas Struktur Data 1

#include
#include
#include

struct data{
int angka;
struct data *next;
}*head=NULL,*tail,*curr;

void pushbelakang(int angka){
curr=(struct data*)malloc(sizeof(struct data));
curr->angka=angka;
if(head==NULL)
{
head=tail=curr;
tail->next=NULL;
}
else{
tail->next=curr;
tail=curr;
tail->next=NULL;
}
}

void print(){
curr=head;
if(head==NULL){
printf(“data kosong”);
}
else
{
while(curr!=NULL)
{
printf(“%d->”,curr->angka);
curr=curr->next;
}
printf(“NULL”);
}

}

int main(){

for(int i=0;i<10;i++){
int input;
printf("\nMasukkan angka yang ingin ditambahkan: ");
scanf("%d",&input);fflush(stdin);

pushbelakang(input);
print();
}
getchar();
return 0;
}

Category: Uncategorized
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=""> <s> <strike> <strong>