1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
kumpel [21]
3 years ago
5

Write a function which sorts the queue in order from the smallest value to the largest value. This should be a modified version

of bubble sort.
Computers and Technology
1 answer:
PilotLPTM [1.2K]3 years ago
7 0

Answer:

#include <iostream>

using namespace std;

void swap(int *a,int *b){    //function to interchange values of 2 variables

   int temp=*a;

   *a=*b;

   *b=temp;

}

void sort(int queue[],int n)

{

   int i,j;

   for(i=0;i<n;i++)      //to implement bubble sort

   {

       for(j=0;j<n-i-1;j++)

       {

           if(queue[j]>queue[j+1])

               swap(queue[j],queue[j+1]);    //to swap values of these 2 variables

       }

   }

}

int main()

{

   int queue[]={6,4,2,9,5,1};

   int n=sizeof(queue)/4;  //to find length of array

   sort(queue,n);

   for(int i=0;i<n;i++)

       cout<<queue[i]<<" ";

   return 0;

}

OUTPUT :

1 2 4 5 6 9

Explanation:

In the above code, Queue is implemented using an array and then passed to a function sort, so that the queue can be sorted in ascending order. In the sort function, in each pass 2 adjacent values are compared and if lower index value is greater than the higher one they are swapped using a swap function that is created to interchange the values of 2 variables.

You might be interested in
Explain how can we determine that where is the strength of magnetic force maximum in a
snow_lady [41]

Answer:

by making a experiment

Explanation:

8 0
3 years ago
What is data consolidation?
Katarina [22]
<span>Data consolidation is the gathering and/or integration of data coming from many and diverse  sources and going into a single destination. Meanwhile this process is taking place,  different data sources are consolidated, into a single data store.

Hope this helps.</span>
8 0
3 years ago
Compression is the action of storing a piece of data with__________ bits.
soldi70 [24.7K]
The answer is fewer because I know a lot about tech I take classes
8 0
3 years ago
Read 2 more answers
BIOS has two jobs. One is to boot up, or start, the computer. What is the other? Maintain the computer’s software firewall. Ensu
Levart [38]

Answer:

Provide the basic interface for the hardware.

Explanation:

3 0
3 years ago
Im not using Brainly for my account how do i Remove it
jeyben [28]
Log in to your account.
Visit your profile settings.
In the Privacy section, click the “Delete Account” button.
5 0
3 years ago
Read 2 more answers
Other questions:
  • What computer system was the first to run the unix operating system?
    11·1 answer
  • What happens if you move unencrypted files into an encrypted folder?
    5·1 answer
  • Programa en C
    9·1 answer
  • Who develop punch card​
    7·1 answer
  • Differences between electromechanical era and electronic era in point.<br>PLZ HELP​
    6·1 answer
  • A seven-octet pattern of alternating 0s and 1s used by the receiver to establish bit synchronization is a _______
    11·1 answer
  • Which wireless communication is typically limited to six feet of distance?
    6·1 answer
  • What is a feature of readable code?
    12·2 answers
  • Basics of visual basic
    15·2 answers
  • unlike the barcode-based tracking system, a radio frequency identification system offers a .
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!