queue and linked list

#include <iostream>
#include <string>
using namespace std;

typedef struct node {
int data;
int id, page, jawatan;
struct node *next;
} nodeQ;

class BarisGilir{
private:
nodeQ *kepala;
nodeQ *ekor;
public:
BarisGilir();
~BarisGilir();
bool kosong();
void tambahQ();
void paparQ();
void printQ();
void hapusQ();
};


BarisGilir::BarisGilir()
{
kepala = NULL;
ekor = NULL;
}


BarisGilir::~BarisGilir()
{
nodeQ *temp = kepala;
while (temp){
cout <<"\n Hapus nod dengan data "<< temp->data;
kepala = temp->next;
delete temp; //nod dihapuskan satu persatu
temp=kepala;
}
}

bool BarisGilir::kosong()
{
return bool(kepala == NULL) ;
}

void BarisGilir::tambahQ()
{
nodeQ *nodbaru, *temp = kepala;
nodbaru = new(nodeQ);
cout << "\nID : ";
cin >> nodbaru->id;
cout << "\n1 - Professor \n2 - Professor Madya \n3 - Pensyarah \n4 - Pelajar \nJawatan : ";
cin >> nodbaru->jawatan;
cout << "\nJumlah halaman : ";
cin >> nodbaru->page;

// nod baru berjaya dicipta
if (kosong()){
//queue kosong
kepala=nodbaru;
}
else {
if (nodbaru->jawatan < temp->jawatan)
{
nodbaru->next = temp;
temp = nodbaru;
if (temp->next == NULL)
{
ekor = nodbaru;
}
temp->next = NULL;
}
else {
temp = temp->next;
}
// else
//{
// //nod baru gagal dicipta
// cout<<"\nTidak dimasukkan krn ingatan tidak mencukupi\n";
//}
}

void BarisGilir::paparQ()
{
struct node *ptr1 = kepala;
if(kepala == NULL)
{
cout<<"Baris Gilir kosong!!";
}
cout<<"\n Baris Gilir\n";
while(ptr1 != NULL)
{
cout<<ptr1->data<<" ->";
ptr1=ptr1->next;
}
cout<<"END";
}

void BarisGilir::hapusQ()
{
int Nilai;
nodeQ *hapusNod, *temp = kepala;

if (kosong())
cout << "\nTiada data dalam senarai\n";
else
{
//queue tidak kosong
Nilai = kepala->data;
temp = kepala;
kepala = kepala->next;
delete(temp); // hapus nod

//jika hapus baris gilir yang ada satu nod
if (!kepala)
ekor = NULL;
}
}

void BarisGilir::printQ()
{
int Nilai;
nodeQ *printNod = kepala;
nodeQ *temp = kepala;

if (kosong())
cout << "\nPenghapusan tidak dapat dilaksanakan";
else
{
//queue tidak kosong
Nilai = kepala->data;
temp = kepala;
kepala = kepala->next;
delete(temp); // hapus nod

//jika hapus baris gilir yang ada satu nod
if (!kepala)
ekor = NULL;
}
}

void menu(int pilihan)
{
cout <<" Masukkan Pilihan Anda:" << endl;
cout <<" 1 > Menambah Cetak"<< endl;
cout <<" 2 > Papar Cetak"<< endl;
cout <<" 3 > Cetak"<< endl;
cout <<" 4 > Padam Cetak"<< endl;
cout <<" 5 > Keluar dari sistem"<< endl;
cout <<" Pilihan Anda ====> "<< endl;
cin>>pilihan;
}


void main()
{
int pilih = 0;
BarisGilir BG;
menu(pilih);
//mendapatkan pilihan operasi
while(pilih != 4)
{
switch (pilih)
{
case 1:
BG.tambahQ();
break;
case 2:
BG.paparQ();
break;
case 3:
BG.printQ();
break;
case 4:
BG.hapusQ();
break;
default :
cout << "Pilihan tiada dalam senarai, pilih semula.";
break;
}//case
}

cout<<">>>>>>keluar dari sistem<<<<<<"<<endl;
}



please help me. is there something wrong?
closed account (o3hC5Di1)
Hi there,

It may just be me, but this looks an awful lot like the code in a question earlier this week.
I will need to ask you the same as that person:

1. Please describe the problem clearly. Asking us "is something wrong" is kind of redundant, you know something is wrong and presumably you get an error or a function doesn't work as you want it to - please tell us.
2. Please put your code in [code ]{code here}[/code] blocks so it will have syntax highlighting - much easier to read.
3. Please use code indentation, again for readability: http://en.wikipedia.org/wiki/Programming_style#Indentation

Also, please tell us what this program is supposed to be doing as you have written it in your own language, which most of use here won't understand.

Thanks!

All the best,
NwN
Topic archived. No new replies allowed.