Uploaded by Nurgül Aykaş

queue

advertisement
QUEUE ÇEVRİMSEL
#include<iostream>
using namespace std;
int front=-1;
int rare=0;
int cnt=0;
int dizi[10];
void main(){
enqueue(2);
enqueue(5);
enqueue(6);
enqueue(8);
yaz();
dequeue();
dequeue();
yaz();
enqueue(6);
enqueue(7);
enqueue(99);
enqueue(41);
enqueue(12);
dequeue();
dequeue();
enqueue(15);
enqueue(26);
enqueue(18);
dequeue();
enqueue(1);
yaz();
for (int i = 0; i < 10; i++)
cout << " " << dizi[i];
system("pause");
void enqueue(int gelen){
if (cnt == 10)
{
cout << "kuyruk dolu";
}
else
{
if (rare == 10)
{
rare = 0;
}
dizi[rare] = gelen;
rare++;
cnt++;
}
}
void dequeue(){
if (cnt == 0)
cout << "kuyruk bos";
else
{
front++;
if (front == 10)
front = 0;
cnt--;
int x = dizi[front];
}
}
void yaz(){
if (front < rare)
{
for (int i = front + 1; i < rare;
i++)
cout << dizi[i] << " ";
}
else
{
for (int i = front + 1; i <10;
i++)
cout << dizi[i] << " ";
for (int i = 0; i < rare; i++)
cout << dizi[i] << " ";
}
}
system("pause");
}
Download