#include
#include
struct link
{
struct link *prev;
struct link *next;
int i;
};
struct link *head;
struct link *now;
struct link *newnode;
struct link *j;
void tahap1()
{
head=(struct link*)malloc(sizeof(struct link));
head->i=1;
head->prev=0;
head->next=0;
now=head;
now->next=(struct link*)malloc(sizeof(struct link));
now->prev=now;
now=now->next;
now->i=3;
now->next=0;
}
void print1()
{
printf(“Tampilan pertama :”);
now=head;
printf(“%d”,now->i);
now=now->next;
printf(“%d\n”,now->i);
}
void tahap2()
{
now=head;
newnode=(struct link*)malloc(sizeof(struct link));
newnode->i=2;
while(now->i != 1)
{
now=now->next;
}
j=now->next;
newnode->next=j;
newnode->prev=now;
now->next=newnode;
j->prev=newnode;
}
void print2()
{
now=head;
printf(“Tampilan kedua :”);
while(now->next !=0)
{
printf(“%d”,now->i);
now=now->next;
}
printf(“%d\n”,now->i);
}
void tahap3()
{
newnode=(struct link*)malloc(sizeof(struct link));
newnode->i=0;
newnode->next=head;
head=newnode;
head->prev=0;
}
void print3()
{
now=head;
printf(“Tampilan ketiga :”);
while(now->next !=0)
{
printf(“%d”,now->i);
now=now->next;
}
printf(“%d\n”,now->i);
}
void tahap4()
{
now=head;
while(now->next !=0)
{now=now->next;
}
now->next=(struct link*)malloc(sizeof(struct link));
now->next->prev=now;
now=now->next;
now->i=5;
now->next=0;
}
void print4()
{
printf(“Tampilan terakhir:”);
now=head;
while(now->next !=0)
{
printf(“%d”,now->i);
now=now->next;
}
printf(“%d\n”,now->i);
}
int main()
{
tahap1();
print1();
tahap2();
print2();
tahap3();
print3();
tahap4();
print4();
getchar();
return 0;
}
Leave a Reply