Tugas Struktur Data 2

#include
#include

struct data{
int angka;
struct data *next;
struct data *prev;
}*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;
head->prev=NULL;
}
else{
tail->next=curr;
curr->prev=tail;
tail=curr;
tail->next=NULL;
}
}

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

head->prev=curr;
curr->next=head;
head=curr;
head->prev=NULL;

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

void pushmid(int angka){
struct data *temp;
temp=head;

if(head==NULL){
printf(“Data Kosong”);
}
else
{
struct data *temp;

curr=(struct data*)malloc(sizeof(struct data));
curr->angka=angka;
head->next=curr;
curr->prev=head;
curr->next=tail;
tail->prev=curr;
tail->next=NULL;
}

}

void main(){
pushdepan(1);
pushbelakang(3);
cetak();
printf(“\n”);
pushmid(2);
cetak();
printf(“\n”);
pushdepan(5);
pushbelakang(0);
cetak();

getchar();
}

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>