Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Nullam eu est quis enim commodo aliquet. Vestibulum eleifend venenatis massa. Curabitur rutrum accumsan felis. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Phasellus ut augue eu purus iaculis viverra. Maecenas vehicula dictum diam.

Read More

Linklist Michael Wijaya 1701293010

#include<stdio.h>
#include<stdlib.h>

struct data{
int x;
struct data* next;
struct data* prev;
}*connector;
void print(){

if(connector!=0)
{
while(connector->next!=0)
{
printf(“%d”,connector->x);
connector = connector->next;
}
printf(“->%d”,connector->x);
}
printf(“\n”);

}
int main()
{
struct data *head;
struct data *tail;
struct data *insert;
//masukkan data 1 dan 3
head =(struct data*)malloc(sizeof(struct data));
tail =(struct data*)malloc(sizeof(struct data));
connector =(struct data*)malloc(sizeof(struct data));
head->x=1;
head->next=0;
head->prev=0;
connector = head;
tail = head;
connector->next =(struct data*)malloc(sizeof(struct data));
connector->prev =(struct data*)malloc(sizeof(struct data));
connector = connector->next;
connector->x=3;
connector->next=0;
connector->prev=head;
tail=connector;

connector = head;
print();
//masukkan data 2 diantara 1 dan 3
connector = head;
if(connector->next!=0){
while(connector->next!=0){
if(connector->x==1&&connector->next->x==3)
{
insert = (struct data*)malloc(sizeof(struct data));
insert->x=2;
insert->next=connector->next;
insert->prev=head->next;
connector->next = insert;
}
}
}
connector = head;
print();
getchar();
//masukkan 0 di depan
connector = head;
insert = (struct data*)malloc(sizeof(struct data));
insert->x=0;
insert->next=head;
head=insert;
connector = head;
print();
//masukkan 5 di paling akhir

insert= (struct data*)malloc(sizeof(struct data));
insert->x = 5;
insert->next = 0;
insert->prev=tail;
tail->next=insert;
tail=tail->next;
connector = head;
print();
getchar();
return 0;
}

Filed under:Uncategorized

Leave a Reply