#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<alloc.h>
void buat_baru();
void insert_kiri();
void insert_kanan();
void tampil();
struct simpul
{
int data;
struct simpul *next;
}
*baru,*awal=NULL, *akhir=NULL, *hapus, *temp;
int main()
{
insert_kiri();
insert_kanan();
insert_kiri();
insert_kiri();
tampil();
return 0;
}
void buat_baru()
{
baru=(simpul*)malloc(sizeof(struct simpul));
cout<<"Masukan Data : ";cin>>baru->data;
baru->next=NULL;
}
void insert_kanan()
{
buat_baru();
if(awal==NULL)
{
awal=baru;
}
else
{
akhir->next=baru;
}
akhir=baru;
akhir->next=NULL;
cout<<endl<<endl;
}
void insert_kiri()
{
buat_baru();
if(awal==NULL)
{
awal=baru;
akhir=baru;
akhir->next=NULL;
}
else
{
baru->next=awal;
awal=baru;
}
cout<<endl<<endl;
}
void tampil()
{
if(awal==NULL)
{
cout<<"kosong";
}
else
{
temp=awal;
while(temp!=NULL)
{
cout<<" Data : "<<temp->data<<"";
temp=temp->next;
}
}
getch();
}
#include<conio.h>
#include<stdio.h>
#include<alloc.h>
void buat_baru();
void insert_kiri();
void insert_kanan();
void tampil();
struct simpul
{
int data;
struct simpul *next;
}
*baru,*awal=NULL, *akhir=NULL, *hapus, *temp;
int main()
{
insert_kiri();
insert_kanan();
insert_kiri();
insert_kiri();
tampil();
return 0;
}
void buat_baru()
{
baru=(simpul*)malloc(sizeof(struct simpul));
cout<<"Masukan Data : ";cin>>baru->data;
baru->next=NULL;
}
void insert_kanan()
{
buat_baru();
if(awal==NULL)
{
awal=baru;
}
else
{
akhir->next=baru;
}
akhir=baru;
akhir->next=NULL;
cout<<endl<<endl;
}
void insert_kiri()
{
buat_baru();
if(awal==NULL)
{
awal=baru;
akhir=baru;
akhir->next=NULL;
}
else
{
baru->next=awal;
awal=baru;
}
cout<<endl<<endl;
}
void tampil()
{
if(awal==NULL)
{
cout<<"kosong";
}
else
{
temp=awal;
while(temp!=NULL)
{
cout<<" Data : "<<temp->data<<"";
temp=temp->next;
}
}
getch();
}
0 comments :
Post a Comment