السلام عليكم ورحمة الله وبركاته
من فرج عن مسلم كربة من كرب الدنيا فرج الله عنه كربة من كرب يوم القيامة
يا أخوان هذا برنامج باستخدام المصفوفة يقوم بإظهار قائمة
1/ اضافة عنصر
2/حذف عنصر
3/ترتيب عنصار المصفوفة
4/بحث عن عنصر
5/ طباعة عنصار المصوصفة
6/خروج
وقد حاولت منذ البارحة وانا احاول اعمل Run للبرنامج يظهر لي اخطاء لا اعرف حلها
وهذي محاولتي :
const int MAX_ITEMS = 10;
class Queue
{
public:
void MakeEmpty();
int Enqueue(int);
int Dequeue();
int sortid ();
int IsFull();
int IsEmpty();
int search (int);
void Print();
private:
int items[MAX_ITEMS];
int front, rear;
};
#include <iostream.h>
#include "Queue.h"
void Queue::MakeEmpty()
{
front = 0;
rear = 0;
}
int Queue::Enqueue(int a)
{
if (IsFull() == 0)
{
items[rear] = a;
if ((rear+1) != MAX_ITEMS)
rear = rear + 1;
}
return 0;
}
int Queue::Dequeue()
{
if (IsEmpty() == 0)
{
front = front + 1;
if (front == MAX_ITEMS)
front = 0;
return 1;
}
return -1;
}
int swap(int &x, int &y);
Int Queue :: sortid ()
{
{ int temp;
temp = x;
x = y;
y = temp;
}
for (int k=0; k<MAX_ITEMS; k++)
{
for (int i=MAX_ITEMS-1; i>k; i--)
{
if (a < a[i-1])
{
swap(a, a[i-1]);
}
}
}
}
int Queue::IsFull()
{
return ( ((rear+1) % MAX_ITEMS) == front);
}
int Queue::IsEmpty()
{
return (front == rear);
}
int Queue :: search (int a ){
for ( int i =0 ; i < MAX_ITEMS; i++){
if ( items==a){
cout << i
}
}
}
void Queue::Print()
{
if (IsEmpty() == 1)
{
cout << "Queue is empty!";
}
else
{
for (int i=front; i<rear; i++)
{
cout << items << endl;
}
}
}
void Queue :: Quit () {
}
int main()
{
Queue 1 ;
int n ;
while (n != 6){
cout << "Enter one number from 1 to 6 >>> 1. Add number …<< endl.. 2. delete number …<< endl..3. sort number << endl ….4. search ….5. print …6.Quit "
cin >>n ;
if ( n == 1){
1. Enqueue(a) ;
}
else if (n==2){
1.Dequeue ();
}
else if (n==3){
1.sort ();
}
else if (n==4){
1.search () ;
}
else if (n==5){
1.print ();
}
}
}