Anda di halaman 1dari 2

Coding

#include <iostream.h>
typedef struct Tnode
{
int value;
Tnode *next;
Tnode *back;
};

Tnode *baru, *bantu,*head,*tail;

void tambah(int value)


{
baru = new Tnode;
baru->next = baru;
baru->back = baru;
baru->value = value;
}
void tambahbelakang(int value){
tambah(value);
if(head == NULL)
head = tail = baru;
else{
tail->next = baru;
baru->back = tail;
tail = baru;
}
tail->next = head;
head->back = tail;
}
void tambahdepan(int value){
tambah(value);
if(head == NULL)
head = tail = baru;
else {
baru->next = head;
head->back = baru;
head = baru;
}
tail->next = head;
head->back = tail;
}

void cetak(){
bantu=head;
do
{
cout<< <<bantu->value<<->;
bantu=bantu->next;
}while(bantu!=head);
cout<<NULL<<endl;
}
void menu(){
int pil;
int isi;
do {
cout <<++<<endl;
cout <<| MENU PILIHAN |<<endl;
cout <<++<<endl;
cout <<| 1. Tambah Depan |<<endl;
cout <<| 2. Tambah Belakang |<<endl;
cout <<| PILIHAN ANDA ? [ ] |<<endl;
cout <<++<<endl;
cin>>pil;
switch(pil){
case 1 :
cout<<Masukkan nilai : ; cin>>isi;
tambahdepan(isi);
cetak();
break;
case 2 :
cout<<Masukkan nilai : ; cin>>isi;
tambahbelakang(isi);
cetak();
break;
case 4 : cout<<Terima kasih;
break;

default:
cout<<Tidak ada pilihan tersebut, masukkan angka dari 1 sampai 3;
}
}while(pil!=4);
}

int main(){
menu();
return 0;
}