Write a program and test a program that translates the following Bubble Sort algorithm to a...

70.2K

Verified Solution

Question

Programming

Write a program and test a program that translates the followingBubble Sort algorithm to a bubblesort function. The function'sprototype is,

void bubblesort(int a[], int size);

Bubble Sort

The inner loop moves the largest element in the unsorted part ofthe array to the last position of the unsorted part of the array;the outer loop moves the last position of the unsorted part of thearray.

The Bubble sort exchanges elements with adjacent elements as itmoves the largest element in the unsorted part of the array to itscorrect position in the sorted part of the array. Once at itscorrect position an element never moves again. An element maychange its position many times before moving to its correctposition.

BubbleSort(A)

  for outer := A.length - 1 to 1

    for inner := 0 to outer –1

      if A[inner] > A[inner +1] then

         temp :=A[inner]

         A[inner]:= A[inner + 1]

         A[inner +1 := temp

      end if

    end for

  end for

end BubbleSort

use this code

#include

#include

#include

#include

#include

using namespace std;


bool fill(int a[], int size,

    uniform_int_distribution&u,

    default_random_engine& e)

{

    if (size < 1)

        returnfalse;

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

            a[i]= u(e);

    

    return true;

}

void show(int a[], int size)

{

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

        cout <

}

void bubblesort(int a[], int size)

{

}

int main()

{

    const int size = 8;

    default_random_engine e;

    uniform_int_distributionu(10, 99);

    int a1d[size];

    fill(a1d, size, u, e);

    show(a1d, size); cout << endl;

    bubblesort(a1d, size);

    show(a1d, size);

    cout << endl;

    system(\"pause\");

    return 0;

}

Answer & Explanation Solved by verified expert
3.9 Ratings (734 Votes)
code in c include include include include include using namespace std bool    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students