#include <iostream.h> #include <conio.h> #include <stdio.h> #include <stdlib.h> int pil; void pilih(); void buat_baru(); void tambah_belakang(); void tambah_depan(); void hapus_belakang(); void hapus_depan(); void tampil(); struct node { char nama [20]; int umur; float tinggi; node *prev, *next; }; node *baru, *head=NULL, *tail=NULL,*hapus,*bantu; void main() { do { clrscr(); cout<<"MENU DOUBLE LINKEDLIST"<<endl; cout<<"1.="" tambah="" depan"<<endl; ="" cout<<"2.="" belakang"<<endl; ="" cout<<"3.="" hapus="" cout<<"4.="" cout<<"5.="" tampilkan"<<endl; ="" cout<<"6.="" selesai"<<endl; ="" cout<<"pilihan="" anda="" :="" "; ="" cin="">>pil; pilih(); } while(pil!=6); } void pilih() { if(pil==1) tambah_depan(); else if(pil==2) tambah_belakang(); else if(pil==3) hapus_depan(); else if(pil==4) hapus_belakang(); else if(pil==5) tampil(); else cout<<"selesai"; } void buat_baru() { baru = new(node); cout<<"input nama : ";cin>>baru->nama; cout<<"input umur : ";cin>>baru->umur; cout<<"input tinggi : ";cin>>baru->tinggi; baru->prev=NULL; baru->next=NULL; } void tambah_belakang() { buat_baru(); if(head==NULL) { head=baru; tail=baru; } else { tail->next=baru; baru->prev=tail; tail=baru; } cout<<endl<<endl; tampil(); }="" void="" tambah_depan() ="" { ="" buat_baru(); ="" if(head="=NULL) " head="baru; " tail="baru; " } ="" else ="" baru-="">next=head; head->prev=baru; head=baru; } cout<<endl<<endl; tampil(); ="" }="" void="" hapus_depan() ="" { ="" if="" (head="=NULL) " cout<<"kosong"; ="" else="" (head-="">next==NULL) { hapus=head; head=NULL; tail=NULL; delete hapus; } else { hapus=head; head=hapus->next; head->prev=NULL; delete hapus; } cout<<endl<<endl; tampil(); ="" }="" void="" hapus_belakang() ="" { ="" if="" (head="=NULL) " cout<<"kosong"; ="" else="" (head-="">next==NULL) { hapus=head; head=NULL; tail=NULL; delete hapus; } else { hapus=tail; tail=hapus->prev; tail->next=NULL; delete hapus; } cout<<endl<<endl; tampil(); }="" void="" tampil() ="" { ="" if="" (head="=NULL) " cout<<"kosong"; ="" else ="" bantu="head; " while(bantu!="NULL) " cout<<"="" nama="" :="" "<<bantu-="">nama; cout<<" umur : "<<bantu->umur; cout<<" tinggi : "<<bantu->tinggi<<endl; bantu="bantu-">next; } } getch(); } What I have tried: <pre>#include <iostream> #include <conio.h> #include <stdio.h> #include <stdlib.h> using namespace std; int pil; void pilih(); void buat_baru(); void tambah_belakang(); void tambah_depan(); void hapus_belakang(); void hapus_depan(); void tampil(); struct node { char nama [20]; int umur; float tinggi; node *prev, *next; }; node *baru, *head=NULL, *tail=NULL,*hapus,*bantu; void main() { do { clrscr(); cout<<"MENU DOUBLE LINKEDLIST"<<endl; cout<<"1.="" tambah="" depan"<<endl; ="" cout<<"2.="" belakang"<<endl; ="" cout<<"3.="" hapus="" cout<<"4.="" cout<<"5.="" tampilkan"<<endl; ="" cout<<"6.="" selesai"<<endl; ="" cout<<"pilihan="" anda="" :="" "; ="" cin="">>pil; pilih(); } while(pil!=6); } void pilih() { if(pil==1) tambah_depan(); else if(pil==2) tambah_belakang(); else if(pil==3) hapus_depan(); else if(pil==4) hapus_belakang(); else if(pil==5) tampil(); else cout<<"selesai"; } void buat_baru() { baru = new(node); cout<<"input nama : ";cin>>baru->nama; cout<<"input umur : ";cin>>baru->umur; cout<<"input tinggi : ";cin>>baru->tinggi; baru->prev=NULL; baru->next=NULL; } void tambah_belakang() { buat_baru(); if(head==NULL) { head=baru; tail=baru; } else { tail->next=baru; baru->prev=tail; tail=baru; } cout<<endl<<endl; tampil(); }="" void="" tambah_depan() ="" { ="" buat_baru(); ="" if(head="=NULL) " head="baru; " tail="baru; " } ="" else ="" baru-="">next=head; head->prev=baru; head=baru; } cout<<endl<<endl; tampil(); ="" }="" void="" hapus_depan() ="" { ="" if="" (head="=NULL) " cout<<"kosong"; ="" else="" (head-="">next==NULL) { hapus=head; head=NULL; tail=NULL; delete hapus; } else { hapus=head; head=hapus->next; head->prev=NULL; delete hapus; } cout<<endl<<endl; tampil(); ="" }="" void="" hapus_belakang() ="" { ="" if="" (head="=NULL) " cout<<"kosong"; ="" else="" (head-="">next==NULL) { hapus=head; head=NULL; tail=NULL; delete hapus; } else { hapus=tail; tail=hapus->prev; tail->next=NULL; delete hapus; } cout<<endl<<endl; tampil(); }="" void="" tampil() ="" { ="" if="" (head="=NULL) " cout<<"kosong"; ="" else ="" bantu="head; " while(bantu!="NULL) " cout<<"="" nama="" :="" "<<bantu-="">nama; cout<<" umur : "<<bantu->umur; cout<<" tinggi : "<<bantu->tinggi<<endl; bantu="bantu-">next; } } getch(); } //Still have error at void main - do - clrscr() //[Error] '::main' must return 'int' //In function 'int main() //[Error] 'clrscr' was not declared in this scope
#include <iostream>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)