السلام عليكم ورحمة الله وبركاته
انا طالب جامعي ادرس حالياً data structure
طُلب مني عمل function Sort خارج لQueue
void Sort(Queue &q)
عمل الفنكشن :
تقوم باستقبال queue يوجد فيه ارقام من نوع انتجر ... ثم تقوم بترتيبهم من الاصغر إلى الاكبر او العكس
حاولت كثيراً لكني لم افلح
حاولت ان تقوم الالفنكسن بنسخ الارقام إلى arrays ثم ترتبهم وتعيدهم إلى الQueue ... واجهت مشكلة في ان سعت الarrays غير محددة
حاولت باستخدام طريقة Recursion Function ... لكن لم افلح في اتقانها
آخر محاوله لي كانت هذه ...
void sort(Queue &Q){
Queue temp;
int max,n;
Q.getFront(max);
Q.remove();
while(!Q.isEmpty()){
Q.getFront();
while(!Q.isEmpty()){
Q.getFront(n);
Q.remove();
if(n>max){
Q.add(max);
max=n;
}
else
Q.add(n);
}
temp.add(max);
Q.getFront(max);
Q.remove();
}لكن واجهتني مشكلة الloop الداخلي كيف إيقافه ؟؟!
اخيراً لجات إلى الانترنت والبحث فوجت هذا المنتدى فوجت فيه الكثير من المبرمجين والكثير من لغات البرمجة ... اتمنى ان نرتقي لكم مستقبلاً
هذا كود الqueue
#include<iostream.h>
const int size=50;
typedef int itemType;
class Queue {
private :
itemType item[size];
int Front,rear,count;
public :
Queue(){Front=0;rear=size-1;count=0;}
Queue(Queue &q);
//void getCounters(int &front,int &rear,int &count,const itemType* &q)
int isEmpty(){return (count==0);}
int isFull(){return (count==size);}
void Print();
int add(itemType);
int remove();
int getFront(itemType &);
};
void Queue::Print(){
if(isEmpty())
cout<<"Empty Queue";
int i,index;
for(i=1,index=Front;i<=count;i++,index=(index+1)%size)
cout<<item[index]<<endl;
}
int Queue::add(itemType newitem){
if(isFull())
return 0;
rear=(rear+1)%size;
item[rear]=newitem;
++count;
return 1;
}
int Queue::remove(){
if(isEmpty())
return 0;
count--;
Front = (Front+1)%size;
return 1;
}
int Queue::getFront(itemType &frontitem){
if(isEmpty())
return 0;
frontitem = item[Front];
return 1;
}
Queue::Queue(Queue &q){
Queue tQ;
itemType tI;
while(q.getFront(tI)){
tQ.add(tI);
q.remove();
}
while(tQ.getFront(tI)){
q.add(tI);
tQ.remove();
}
}ملاحظة :
لقد قرأة "قواعد طرح المواضيع "
انا لا اطلب منكم حل لي هذه function ... ولا طلب كودها
لكن اطلب مساعدتي في الفكرة اللتي يمكن الحل بها
والسلام عليكم ورحمة الله وبركاته