Queue Cingular link list

Posted: Minggu, 23 Mei 2010 by Vektor in Label:
0

Nih Program Quuue Cingular link list c++
Mudah2an bisa membantu kalian...
klo ada kekurangan mohon comentnya ya...
sama2 masih belajar..hehehe


#include "stdio.h"
#include "conio.h"
#include "iostream.h"

typedef struct Tnode
{
int value;
Tnode *next;
Tnode *back;

}Tnode;




Tnode *baru, *bantu,*head,*tail;

void tambah(int value)
{
baru = new Tnode;
baru->next = baru;
baru->back = baru;
baru->value = value;
}

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


void tambahbelakang(int value){
tambah(value);
if(isEmpty()==1){
head=baru;
tail=baru;
head->next = head;
head->back = head;
tail->next = tail;
tail->back = tail;
}
else {
tail->next = baru;
baru->back = tail;
tail = baru;
tail->next = head;
head->back = tail;
}

}


void tambahdepan(int value){
tambah(value);
if (isEmpty()==1) {
head=baru;
tail=head;
head->next=head;
head->back=head;
tail->next=tail;
tail->back=tail;
}
else {
baru->next=head;
head->back=baru;
head=baru;
head->back=tail;
tail->next=head;
}

}

void hapusDepan(){
Tnode *hapus; ;
int d;

if (isEmpty()==0){
if(head != tail){
hapus = head;
d = hapus->value;
head = head->next;
tail->next = head;
head->back = tail;
delete hapus;
}
else {
d = head->value;
head = NULL;
tail = NULL;
}
cout<<"Data Terdepan Terhapus"; } else cout<<"Masih Kosong"; } void cetak(){ bantu = head; if(isEmpty()==0) do { cout<<"bantu->value;
bantu = bantu->next;
}while(bantu!=head);
else cout<<"Data Kosong "; } void menu(){ int pil; int isi; do { cout<<"\n==================Queue Cingular Link LIst======================"; cout<<"\nCara Pengunaan :"; cout<<"\n1. Setiap Data yang di inputkan berjumlah satu data (1 frekuensi)"; cout<<"\n2. Jika Data lebih dari satu maka pilih menu input lagi untuk memasukan data"; cout<<"\n\n============================================================="; cout<<"\nMENU"; cout<<"\n1. Input Dari Depan"; cout<<"\n2. Input Dari Belakang"; cout<<"\n3. Hapus Data"; cout<<"\n4. Cetak"; cout<<"\n5. Keluar"; cout<<"\n============================================================="; cout<<"\nMasukan Pilihan Anda : "; cin>>pil;

clrscr();
switch(pil){
case 1 :
cout<<"Masukkan nilai : "; cin>>isi;
tambahdepan(isi);
break;
case 2 :
cout<<"Masukkan nilai : "; cin>>isi;;
tambahbelakang(isi);
break;
case 3 : hapusDepan();
break;
case 4 : cetak();
break;
case 5 : cout<<"Terima kasih"; break; default: cout<<"Tidak ada pilihan tersebut, masukkan angka dari 1 sampai 4"; } }while(pil!=5); } int main(){ menu(); return 0; }



Downloads Programs :
Link : http://www.4shared.com/file/RsysPQjM/Queue_Cingular_Link_List_08090.html

0 komentar: