Professional Documents
Culture Documents
Buat Program Yang Sejenis Untuk Queue
Buat Program Yang Sejenis Untuk Queue
# include <iostream.h>
# include <conio.h>
class Linked_list_Queue
{
private:
struct node {
int data;
node *next;
};
node *rear;
node *entry;
node *print;
node *front;
public:
Linked_list_Queue( );
void Delete( );
void Insert( );
void print_list( );
void show_working( );
};
Linked_list_Queue::Linked_list_Queue ( )
{
rear=NULL;
front=NULL;
}
void Linked_list_Queue::Insert( )
{
int num;
cout<<"\n\n\n\n\n\t Masukkan angka dalam Queue : ";
cin>>num;
entry=new node;
if(rear==NULL)
{
entry->data=num;
entry->next=NULL;
rear=entry;
front=rear;
}
else
{
entry->data=num;
entry->next=NULL;
rear->next=entry;
rear=entry;
}
cout<<"\n\n\t *** "<<num<<" sudah masuk dalam
Queue."<<endl;
cout<<"\n\n\n\t\t Pres any key to return to Menu. ";
getch( );
}
void Linked_list_Queue::Delete( )
{
if(front==NULL)
cout<<"\n\n\n\t *** Error : Queue is empty.
\n"<<endl;
else
{
int deleted_element=front->data;
node *temp;
temp=front;
front=front->next;
delete temp;
cout<<"\n\n\n\t *** "<<deleted_element<<"
dihapus dari Queue."<<endl;
}
cout<<"\n\n\n\t\t Pres any key to return to Menu. ";
getch( );
}
void Linked_list_Queue::print_list( )
{
print=front;
if(print!=NULL)
cout<<"\n\n\n\n\n\t Angka-angka yang ada dalam Queue
adalah : \n"<<endl;
else
cout<<"\n\n\n\n\n\t *** Tidak ada yang
ditampilkan. "<<endl;
while(print!=NULL)
{
cout<<"\t "<<print->data<<endl;
print=print->next;
}
cout<<"\n\n\n\t\t Pres any key to return to Menu. ";
getch( );
}
Input:
gotoxy(10,20);
cout<<" ";
gotoxy(10,20);
cout<<"Masukkan Pilihan : ";
Key=getche( );
if(int(Key)==27 || Key=='e' || Key=='E')
break;
else if(Key=='i' || Key=='I')
Insert( );
else if(Key=='d' || Key=='D')
Delete( );
else if(Key=='p' || Key=='P')
print_list( );
else
goto Input;
}
while(1);
}
int main( )
{
Linked_list_Queue obj;
obj.show_working( );
return 0;
}