السلام عليكم
هذا الكود ل round robin
بالداتا عن طريق ال linkedlist
اتممت الحل على هذا النحو
ولكن حقيقة لا اعلم اين الخطأ في الكود ؟؟.. و احترت كيف افعل به
لذلك لجأت لكم هنا
و اتمنى جدا ان تساعدوني بأقرب وقت
و توضحوا لي اخطائي
بالانتظار
#include <iostream>
using namespace std;
class nod
{public:
int data;
nod *next;
nod *prev;
nod(int x)
{
next= NULL;
prev= NULL;
data=x;
}
};
class queu{
public:
nod *h;
queu()
{h=NULL;}
bool empty()
{
if (h->next == h->prev)
return 1;
else
return 0;
}
void enqueu (int num)
{
int x;
nod *temp;
temp = new nod(x);
temp ->data = num;
if (h == NULL){
h =temp;
h ->next =h;
h->prev =h;}
else{
h->prev->next=h;
temp->prev=h->prev;
h->prev=temp;
temp->next=h;}
}
int Dequeue()
{ int temp;
temp= h->data;
if( h== h->prev )
{
delete h;
h=NULL;}
else {
nod *h2;
h2=h->next;
h->next->prev=h->prev;
h->prev->next=h->next;
h->next=NULL;
h->prev=NULL;
delete h;
h=h2;
}return temp;
}
void print()
{
nod *p=h;
while (p!=NULL)
{
cout<<p->data;
p=p->next;}
}
};
void main()
{
int x;
queu obj;
int choice,time_slice ,cpu_time;
cin>>x;
cout<<"1.enter 1 to insert cpu time\n 2.enter 2 to insert the time slice . \n 3- enter 3 to perform RR algorethem ";
cin>>choice;
while (choice>0){
switch (choice)
{
case 1:
cin>>cpu_time;break;
case 2:
cin>>time_slice;break;
case 3:
while(!obj.empty());
{
x= obj.Dequeue();
x=x - time_slice;
if(x>0)
obj.enqueu(x);
obj.print();
}
break;
default :
cout<<"try again";
}
cin>>choice;
}
}