9. Form a model of queue using: a) array representation; b) circular queue; c) l
ID: 1947529 • Letter: 9
Question
9. Form a model of queue using:a) array representation;
b) circular queue;
c) linked representation,
make a description of it and develope 3 queue processing operations:
a) Retrieve - to retrieve the element containg key value tkey without deleting of it;
Cancel - to delete the i-th element;
Top - to move the i-th element to the beginning of queue;
b) Retrieve - to retrieve the i-th element without deleting of it;
Cancel - to delete the element containg key value tkey;
Swap to move the element containing key value tkey to the beginning of queue
Explanation / Answer
#include <iostream>
using namespace std;
#define maxsize 100
int main(void)
{
int temp, i, j, n, list[maxsize];
cout<<" --You are prompted to enter your list size.--";
cout<<" --Then, for your list size, you are prompted to enter--";
cout<<" --the element (integers) of your list.--";
cout<<" --Finally your list will be sorted ascending!!!-- ";
// enter the list's size
cout<<" Enter your list size: ";
// read the list's size
cin>>n;
// prompting the data from user store in the list
for(i=0; i<n; i++)
{
cout<<"Enter list's element #"<<i<<"-->";
cin>>list[i];
}
// do the sorting...
for(i=0; i<n-1; i++)
for(j=i+1; j<n; j++)
if(list[i] > list[j])
{
// These three lines swap the elements
// list[i] and list[j].
temp = list[i];
list[i] = list[j];
list[j] = temp;
}
cout<<" Sorted list, ascending: ";
for(i=0; i<n; i++)
cout<<" "<<list[i];
cout<<endl;
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.