Ini adalah tugas Struktur Data dari I Wayan Gede Aryarthana atau biasa di panggil Brim 183 maunya tapi sering di panggil Brim aja. dalam mengerjakan tugas ini I Wayan Gede Aryarthana belajar dari materi materi yang di peroleh dari Internet dalam bentuk file PDF. untuk itu I Wayan Gede Aryarthana mengucapkan terima kasih kepada sumber sumber yang telah dengan sukarela arsipnya untuk di pelajari secara umum.

/*********************************************************************************
* Nama Program : Implementasi Stack Dan Queue Non circular
* Menggunakan Linked List Non Circular
* Nama : I Wayan Gede Aryarthana
* Tanggal : 15 November 2008
* Versi : 1.0
**********************************************************************************/


#include<iostream>
using namespace std;

struct TNode
{
int data;
TNode *next;
};

TNode*head;

void init()
{
head = NULL;
}

int isEmpty()
{
if(head == NULL)
return 1;
else
return 0;
}

void push(int inputan)
{
TNode *baru;
baru = new TNode;
baru->data = inputan;
baru->next = head;
head = baru;
}


void pop()
{

TNode *bantu;
int data;
if (isEmpty()==0)
{
bantu = head;
data = bantu -> data;
head = head -> next;
delete bantu;
}else cout<<"Data kosong\n";
}

void dequeue()
{
TNode *hapus,*bantu;
int data;
if (isEmpty()==0)
{
if(head->next != NULL)
{
bantu = head;
while(bantu->next->next!=NULL)
{
bantu = bantu->next;
}
hapus = bantu->next;
data = hapus->data;
bantu->next = NULL;
delete hapus;
}
} else
cout<<"Masih kosong\n";
}

void printstack()
{
TNode *bantu;
bantu = head;
if (isEmpty()==0)
{
while (bantu != NULL)
{
cout<<bantu->data;
cout<<endl;
bantu = bantu->next;
}
}
else cout<<"Data kosong\n";
}

void printqueue()
{
TNode *bantu;
bantu = head;
if (isEmpty()==0)
{
while (bantu != NULL)
{
cout<<" "<<bantu->data;
bantu = bantu->next;
}
}
else cout<<"Data kosong\n";
}


void clear()
{
TNode *bantu,*hapus;
bantu = head;
if (isEmpty()==0)
{
while(bantu!=NULL)
{
hapus = bantu;
bantu = bantu->next;
delete hapus;
}
head = NULL;
}
else cout<<"Data kosong\n";
}

void mainstack()
{
int inputan,menu;
do
{
cout<<" ______________ \n";
cout<<"| MENU PROGRAM |\n";
cout<<"|______________|\n";
cout<<"1. Push\n";
cout<<"2. Pop\n";
cout<<"3. Clear\n";
cout<<"4. Print\n";
cout<<"5. Exit\n";
cout<<"menu : ";
cin>>menu;
if (menu<1||menu>5)
{
cout<<"\n Maaf..pilihan anda salah!!!tolong ulangi lagi!!\n\n";
}
else
{
switch (menu)
{
case 1 :
{
cout<<"Masukkan data= ";
cin>>inputan;
push(inputan);
cout<<endl<<endl;

}
break;
case 2 :
{

cout<<endl;
pop();
cout<<endl;
}
break;
case 3 :
{
cout<<endl;
clear();
cout<<endl;
}
break;
case 4 :
{
cout<<endl;
printstack();
cout<<endl;
}
break;
}
}

}while(menu!=5);
clear();
}

void mainqueue()
{
int inputan,menu;
do
{
cout<<" _____________\n";
cout<<"| MENU PROGRAM|\n";
cout<<"|_____________|\n";
cout<<"1. Queue\n";
cout<<"2. Dequeue\n";
cout<<"3. Clear\n";
cout<<"4. Print\n";
cout<<"5. Exit\n";
cout<<"menu : ";
cin>>menu;
if (menu<1||menu>5)
{
cout<<"\n Maaf..pilihan anda salah!!!tolong ulangi lagi!!\n\n";
}
else
{
switch (menu)
{
case 1 :
{
cout<<"Masukkan data= ";
cin>>inputan;
push(inputan);
cout<<endl<<endl;

}
break;
case 2 :
{
cout<<endl;
dequeue();
cout<<endl;
}
break;
case 3 :
{
cout<<endl;
clear();
cout<<endl;
}
break;
case 4 :
{
cout<<endl;
printqueue();
cout<<endl<<endl;
}
break;
}
}
}while(menu!=5);
clear();
}

void main()
{
int menu;
do
{
cout<<"\t________________________________________________________________ "<<endl;
cout<<"\t|| ||"<<endl;
cout<<"\t|| IMPLEMENTASI SINGLE STACK DAN QUEUE NON CIRCULAR ||"<<endl;
cout<<"\t|| MENGGUNAKAN SINGLE LINKED LIST NON CIRCULAR ||"<<endl;
cout<<"\t|| ||"<<endl;
cout<<"\t________________________________________________________________"<<endl<<endl<<endl;

cout<<" MENU UTAMA \n";
cout<<"________________________________________________________\n";
cout<<"1. Linked List Non Circular Dengan Stack \n";
cout<<"2. Linked List Non Circular Dengan Queue Non Circular \n";
cout<<"3. Exit \n";
cout<<endl;
cout<<"Masukan pilihan anda!! : ";
cin>>menu;
cout<<endl;
if (menu<1||menu>3)
{
cout<<"\n Maaf..pilihan anda salah!!!tolong ulangi lagi!!\n\n";
}
else
{
switch (menu)
{
case 1 :
{
cout<<endl<<endl;
mainstack();
cout<<endl<<endl;

}
break;
case 2 :
{
cout<<endl<<endl;
mainqueue();
cout<<endl<<endl;
}
break;
}
}

}while(menu!=3);
}

jika ada kesalahan harap maklum

Posting Komentar

[+] Komentar membangun lebih disukai
[+] Admin akan menghapus komentar yang melecehkan, kasar, dan bertendensi SARA.
[+] Selain Admin, link aktif dalam komentar akan dihapus

 
Top