Click here to Skip to main content
15,746,302 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
#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
Posted
Updated 2-Jan-22 2:03am

1 solution

iostream.h isn;t a part of "Standard C++" - it was a part of some early compilers so it tends to be used only with very ancient code (early 90's or before).

Instead, try
C++
#include <iostream> 
 
Share this answer
 
Comments
Member 15486346 2-Jan-22 9:21am    
I already use that dan add "using namespace std;" but still error:
void main - do - clrscr()
[Error] '::main' must return 'int'
In function 'int main()
[Error] 'clrscr' was not declared in this scope
OriginalGriff 2-Jan-22 9:57am    
Read what you said...
"Main must return int" - add "return 0;" to the end of the function ...

"clrscr" is part of TurboC (an ancient C compiler) and there is no equivalent in "standard C++"
There may be a way in the specific package and OS you are using, but we have no idea what that is:
https://www.google.com/search?q=c%2B%2B+console+clear+screen&oq=c%2B%2B+console+clear+scvreen&aqs=chrome.1.69i57j0i13j0i22i30l3.6495j0j7&sourceid=chrome&ie=UTF-8

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900