Merupakan Program Struktur Data Menggunakan Bahasa C, Bisa Di Buat Tugas Akhir :)
Algoritma
- Memulai program.
- Membuat percabangan jika ingin mencabangkan program dari awal sampai akhir dengan menggunakn (Sorting,double linklist head tail,dan swich case).
- Tampilan Menu pilihan program
cout<<"
=============================\n";
cout<<"\n
TOKO BUTIK khusnulkhotimah\n";
cout<<"\t\t\t<<<MENU>>>\n";
cout<<"
|----------------|-------------------|-------------|\n";
cout<<"
|1.masukkan Depan|
|2.lihat data |\n";
cout<<"
|----------------|-------------------|-------------|\n";
cout<<"
|3.hapus Depan |4.hapus Belakang |5.hapus semua|\n";
cout<<"
|----------------|-------------------|-------------|\n\n";
cout<<"\tKeterangan
barang yang bisa dimasukkan\n";
cout<<"
|----------------|-------------------|-----------|\n";
cout<<"
|1.baju laki-laki|2.celana
|3.jas |\n";
cout<<"
|----------------|-------------------|-----------|\n";
cout<<"
|4.jacket |5.baju wanita |6.kerudung |\n";
cout<<"
|----------------|-------------------|-----------|\n";
cout<<"\n
pilih menu = ";cin>>P;
4. Memilih Pilihan (1-5).
5. Jika pilihan (1) maka akan
tampil pengisian data:
cout<<"
=============================\n";
cout<<"\n
TOKO BUTIK khusnul khotimah\n";
cout<<"\t\t\t<<<MENU>>>\n";
cout<<"
|----------------|-------------------|-------------|\n";
cout<<"
|1.masukkan Depan|
|2.lihat data |\n";
cout<<"
|----------------|-------------------|-------------|\n";
cout<<"
|3.hapus Depan |4.hapus Belakang |5.hapus semua|\n";
cout<<"
|----------------|-------------------|-------------|\n\n";
cout<<"\tKeterangan
barang yang bisa di masukkan\n";
cout<<"
|----------------|-------------------|-----------|\n";
cout<<"
|1.baju laki-laki|2.celana
|3.jas |\n";
cout<<"
|----------------|-------------------|-----------|\n";
cout<<"
|4.jacket |5.baju wanita |6.kerudung |\n";
cout<<"
|----------------|-------------------|-----------|\n";
cout<<"\n pilih menu = ";cin>>P;
Pilih
Menu = 1
Masukan
kode barang =1
Success….. data sudah masuk….
1.:
BAJU LAKI-LAKI: 1
- Jika pilihan (2), maka data yang diinputkan maka akan muncul tampilan:
cout<<"
=============================\n";
cout<<"\n
TOKO BUTIK khusnul khotimah\n";
cout<<"\t\t\t<<<MENU>>>\n";
cout<<"
|----------------|-------------------|-------------|\n";
cout<<"
|1.masukkan Depan|
|2.lihat data |\n";
cout<<"
|----------------|-------------------|-------------|\n";
cout<<"
|3.hapus Depan |4.hapus Belakang |5.hapus semua|\n";
cout<<"
|----------------|-------------------|-------------|\n\n";
cout<<"\tKeterangan
barang yang bisa di masukkan\n";
cout<<"
|----------------|-------------------|-----------|\n";
cout<<"
|1.baju laki-laki|2.celana
|3.jas |\n";
cout<<"
|----------------|-------------------|-----------|\n";
cout<<"
|4.jacket |5.baju wanita |6.kerudung |\n";
cout<<"
|----------------|-------------------|-----------|\n";
cout<<"\n
pilih menu = ";cin>>P;
pilih
menu =2
5 4 3 2 1
- Jika pilihan (3), maka data yang diinputkanatau yang di isiakan di hapusDepan (cancel).
- Jika pilihan (4), maka data yang diinputkanatau yang di isiakan di hapusBelekang (cancel).
- Jika pilihan (5), maka data yang diinputkanatau yang di isiakan di hapusSemua (cancel).
Program Listing
#include <iostream>
typedef struct tnode{
int data;
tnode *next;
tnode *prev;
}tnode;
tnode *head, *tail;
void init(){
head = NULL;
tail =NULL;
}
int isEmpty(){
if(tail == NULL) return 1;
else return 0;
}
void tampil(){
tnode *bantu;
bantu = head;
if(isEmpty()==0){
while(bantu!=tail->next){
cout<<bantu->data<<" ";
bantu=bantu->next;
}
cout<<endl;
} else cout<<"Masih kosong\n";
}
void insertDepan (int databaru){
tnode *baru;
baru = new tnode;
baru->data = databaru;
baru->next = NULL;
baru->prev = NULL;
if(isEmpty()==1){
head=baru;
tail=head;
head->next = NULL;
head->prev = NULL;
tail->prev = NULL;
tail->next = NULL;
}
else {
baru->next = head;
head->prev = baru;
head = baru;
}
cout<<"succses... data sudah masuk...\n";
}
void hapusBelakang(){
tnode *hapus;
int d;
if (isEmpty()==0){
if(head->next != NULL){
hapus = tail;
d = tail->data;
tail = tail->prev;
tail->next = NULL;
delete hapus;
} else {
d = head->data;
head = NULL;
tail = NULL;
}
cout<<d<<" terhapus\n";
} else cout<<"Masih kosong\n";
}
void hapusDepan(){
tnode *hapus;
int d;
if (isEmpty()==0){
if(head->next != NULL){
hapus = head;
d = hapus->data;
head = head->next;
head->prev = NULL;
delete hapus;
} else {
d = head->data;
head = NULL;
tail = NULL;
}
cout<<d<<" terhapus\n";
} else cout<<"Masih kosong\n";
}
void clear(){
tnode *bantu,*hapus;
bantu = head;
while(bantu!=NULL){
hapus = bantu;
bantu = bantu->next;
delete hapus;
}
head = NULL;
tail = NULL;
}
main()
{
int P;
int newdata;
int L;
do
{
cout<<"\n TOKO BUTIK khusnul khotimah\n";
cout<<" =============================\n";
cout<<"\t\t\t<<<MENU>>>\n";
cout<<" |----------------|-------------------|-------------|\n";
cout<<" |1.masukkan Depan| |2.lihat data |\n";
cout<<" |----------------|-------------------|-------------|\n";
cout<<" |3.hapus Depan |4.hapus Belakang |5.hapus semua|\n";
cout<<" |----------------|-------------------|-------------|\n\n";
cout<<"\tKeterangan barang yang bisa dimasukkan\n";
cout<<" |----------------|-------------------|-----------|\n";
cout<<" |1.baju laki-laki|2.celana |3.jas |\n";
cout<<" |----------------|-------------------|-----------|\n";
cout<<" |4.jacket |5.baju wanita |6.kerudung |\n";
cout<<" |----------------|-------------------|-----------|\n";
cout<<"\n pilih menu = ";cin>>P;
cout<<"\n";
switch(P)
{
case 1 :
{
cout<<"\n masukkan kode barang = ";cin>>L;
insertDepan(L);
switch(L)
{
case 1 :
{
cout<<"1.|BAJU LAKI-LAKI|\n";
break;
}
case 2 :
{
cout<<"2.|CELANA|\n";
break;
}
case 3 :
{
cout<<"3.|JAS|\n";
break;
}
case 4 :
{
cout<<"4.|JAKET|\n";
break;
}
case 5 :
{
cout<<"5.|BAJU WANITA|\n";
break;
}
case 6 :
{
cout<<"6.|KERUDUNG|\n";
break;
}
default :
{
cout<<"pilihan anda salah";
break;
}
}
case 2 :
{
tampil();
cout<<"\n";
break;
}
case 3 :
{
hapusDepan();
break;
}
case 4 :
{
hapusBelakang();
break;
}
case 5 :
{
clear();
break;
}
default :
cout<<"\n Choise Not Found";
cout<<"\n EXIT ";
break; }
} }
while(P>0&&P<7);
}
typedef struct tnode{
int data;
tnode *next;
tnode *prev;
}tnode;
tnode *head, *tail;
void init(){
head = NULL;
tail =NULL;
}
int isEmpty(){
if(tail == NULL) return 1;
else return 0;
}
void tampil(){
tnode *bantu;
bantu = head;
if(isEmpty()==0){
while(bantu!=tail->next){
cout<<bantu->data<<" ";
bantu=bantu->next;
}
cout<<endl;
} else cout<<"Masih kosong\n";
}
void insertDepan (int databaru){
tnode *baru;
baru = new tnode;
baru->data = databaru;
baru->next = NULL;
baru->prev = NULL;
if(isEmpty()==1){
head=baru;
tail=head;
head->next = NULL;
head->prev = NULL;
tail->prev = NULL;
tail->next = NULL;
}
else {
baru->next = head;
head->prev = baru;
head = baru;
}
cout<<"succses... data sudah masuk...\n";
}
void hapusBelakang(){
tnode *hapus;
int d;
if (isEmpty()==0){
if(head->next != NULL){
hapus = tail;
d = tail->data;
tail = tail->prev;
tail->next = NULL;
delete hapus;
} else {
d = head->data;
head = NULL;
tail = NULL;
}
cout<<d<<" terhapus\n";
} else cout<<"Masih kosong\n";
}
void hapusDepan(){
tnode *hapus;
int d;
if (isEmpty()==0){
if(head->next != NULL){
hapus = head;
d = hapus->data;
head = head->next;
head->prev = NULL;
delete hapus;
} else {
d = head->data;
head = NULL;
tail = NULL;
}
cout<<d<<" terhapus\n";
} else cout<<"Masih kosong\n";
}
void clear(){
tnode *bantu,*hapus;
bantu = head;
while(bantu!=NULL){
hapus = bantu;
bantu = bantu->next;
delete hapus;
}
head = NULL;
tail = NULL;
}
main()
{
int P;
int newdata;
int L;
do
{
cout<<"\n TOKO BUTIK khusnul khotimah\n";
cout<<" =============================\n";
cout<<"\t\t\t<<<MENU>>>\n";
cout<<" |----------------|-------------------|-------------|\n";
cout<<" |1.masukkan Depan| |2.lihat data |\n";
cout<<" |----------------|-------------------|-------------|\n";
cout<<" |3.hapus Depan |4.hapus Belakang |5.hapus semua|\n";
cout<<" |----------------|-------------------|-------------|\n\n";
cout<<"\tKeterangan barang yang bisa dimasukkan\n";
cout<<" |----------------|-------------------|-----------|\n";
cout<<" |1.baju laki-laki|2.celana |3.jas |\n";
cout<<" |----------------|-------------------|-----------|\n";
cout<<" |4.jacket |5.baju wanita |6.kerudung |\n";
cout<<" |----------------|-------------------|-----------|\n";
cout<<"\n pilih menu = ";cin>>P;
cout<<"\n";
switch(P)
{
case 1 :
{
cout<<"\n masukkan kode barang = ";cin>>L;
insertDepan(L);
switch(L)
{
case 1 :
{
cout<<"1.|BAJU LAKI-LAKI|\n";
break;
}
case 2 :
{
cout<<"2.|CELANA|\n";
break;
}
case 3 :
{
cout<<"3.|JAS|\n";
break;
}
case 4 :
{
cout<<"4.|JAKET|\n";
break;
}
case 5 :
{
cout<<"5.|BAJU WANITA|\n";
break;
}
case 6 :
{
cout<<"6.|KERUDUNG|\n";
break;
}
default :
{
cout<<"pilihan anda salah";
break;
}
}
case 2 :
{
tampil();
cout<<"\n";
break;
}
case 3 :
{
hapusDepan();
break;
}
case 4 :
{
hapusBelakang();
break;
}
case 5 :
{
clear();
break;
}
default :
cout<<"\n Choise Not Found";
cout<<"\n EXIT ";
break; }
} }
while(P>0&&P<7);
}
0 comments