الســــلام عليكم :
أخواني وأخواتي :
أنا أدرس مادة هياكل البيانات .. ، وعملت برنامج ولكني لأ أعرف أين الخطأ فيه
أتمنى مساعدتي :
البرنامج الذي عملته :
#ifndef INTQUEUE_H
#define INTQUEUE_H
class IntQueue
{
private:
int *queueArray;
int queueSize;
int front;
int rear;
int numItems;
public:
IntQueue(int);
~IntQueue(void);
void enqueue(int);
void dequeue(int &);
bool isEmpty(void);
bool isFull(void);
void clear(void);
};
#include <iostream.h>
#include "IntQueue.h“
//*************************
// Constructor *
//*************************
IntQueue::IntQueue(int s)
{
queueArray = new int
queueSize = s;
front = 0;
rear = 0;
numItems = 0;
}
IntQueue::~IntQueue(void)
{
delete [] queueArray;
}
void IntQueue::enqueue(int num)
{
if (isFull())
cout << "The queue is full.\n";
else
{
// Calculate the new rear position
rear = (rear + 1) % queueSize;
// Insert new item
queueArray[rear] = num;
// Update item count
numItems++;
}
}
void IntQueue::dequeue(int &num)
{
if (isEmpty())
cout << "The queue is empty.\n";
else
{
// Move front
front = (front + 1) % queueSize;
// Retrieve the front item
num = queueArray[front];
// Update item count
numItems--;
}
}
bool IntQueue::isEmpty(void)
{
bool status;
if (numItems)
status = false;
else
status = true;
return status;
}
void IntQueue::clear(void)
{
front = queueSize - 1;
rear = queueSize - 1;
numItems = 0;
}
#include <iostream.h>
#include "intqueue.h“
void main(void)
{
IntQueue iQueue(5);
cout << "Enqueuing 5 items...\n";
for (int x = 0; x < 5; x++)
iQueue.enqueue(x);
cout << "Now attempting to enqueue again...\n";
iQueue.enqueue(5);
cout << "The values in the queue were:\n";
while (!iQueue.isEmpty())
{
int value;
iQueue.dequeue(value);
cout << value << endl;
}
}
طبعاً كل هذا العمل ببرنامج Borland C++ وهو برنامج شبيه بالــ C++
أتمنى المساعده وشكراً
