File : queue_pointer.cpp
Author : Jemmy R. Mongi
Date : 18 September 2012
*/
#include <iostream>
#include <conio.h>
#include <stdio.h>
using namespace std;
struct node
{
int data;
node *link;
};
node *front = NULL;
node *rear = NULL;
void Insertion()
{
node *temp;
cout<< "Masukan nilai : ";
cin>>temp->data;
temp->link = NULL;
//if(front == NULL)
//{
//front = temp;
//rear = temp;
//}
//else
//{
rear->link = temp;
temp = rear->link;
//}
}//end insertion
void Deletion()
{
node *temp;
if(front == NULL && rear == NULL)
{
system("cls");
cout<<"Error, cannot delete, because Queue is empty\n";
}
else
{
temp = front;
front = front->link;
cout << "Number to be delete is : \n"<< temp->data;
free(temp);
if(front == NULL)
{
rear = NULL;
}
}
}//end deletion
void Display()
{
node *temp;
if(front == NULL && rear == NULL)
{
system("cls");
cout<< "error cannot display, because Queue is Empty\n";
}
else
{
temp = front;
cout<< "elements in queue is : ";
while(temp != NULL)
{
cout<
}
temp = temp->link;
}
}
//fungsi utama
int main()
{
int pilih;
while(pilih != 4)
{
cout<<"Queue Pointer\n";
cout<<"1. Insert\n";
cout<<"2. Delete\n";
cout<<"3. Display\n";
cout<<"4. Exit\n";
cout<<"Masukan pilihan anda : ";
cin>>pilih;
switch(pilih)
{
case 1 :
Insertion();
break;
case 2 :
Deletion();
break;
case 3 :
Display();
break;
case 4 :
exit(0);
break;
default :
system("cls");
cout<<"maaf, pilihan tidak tersedia\n";
}
}
system("pause");
return 0;
}//end fungsi utama
No comments:
Post a Comment