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
Websites whose URL’s contain tildes (~) are usually published by the government. TRUE or FALSE.
ludmilkaskok [199]
False, anyone who makes a website could use a tilde to signify a file name.
8 0
3 years ago
Read 2 more answers
Fill in the blank with the correct response.
Karo-lina-s [1.5K]

Answer:

logical

Explanation:

4 0
2 years ago
Read 2 more answers
video-sharing sotes such as youtube and vimeo provide a place to post short videos called clips true or false?
olya-2409 [2.1K]
I would say True ! I hope i helped!
4 0
3 years ago
Please tell fast plzzzzzzzz​
Verdich [7]

Answer:

window.............

6 0
2 years ago
Read 2 more answers
Which of the listed tools would a barber likely use in the following scenario?
Charra [1.4K]

Answer:

Please elaborate more your question so I can answer your question accurately.

Explanation:

6 0
2 years ago
Other questions:
  • When using the “reply all” option, your message will automatically be sent to ____ recipients of the original message. ​?
    7·2 answers
  • How i can connect to internet automatically when i switch on my computer?
    8·1 answer
  • To have the most impact when using email, you should structure your messages so that
    5·1 answer
  • 1. What are copyright laws? (6 points)
    15·1 answer
  • Integer indexing array: Weekend box office The row array movieBoxOffice stores the amount of money a movie makes (in millions of
    11·1 answer
  • Which of these is the fastest transmission medium?
    11·2 answers
  • Most effective way of closing email is<br>​
    7·2 answers
  • Who is the best nfl team in your mind
    14·2 answers
  • What are different social phenomenas are you aware of that used part of a social movement, change, or cause
    14·1 answer
  • Data becomes _____ when it is presented in a context so that it can answer a question or support decision makin
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!