C++ (data structure using c++). please send me copyable file. Write a program and test a program...

60.1K

Verified Solution

Question

Programming

C++ (data structure using c++). please send me copyablefile.

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

program:

#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)

return false;

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 << a[i] << ' ';

}

void bubblesort(int a[], int size)

{

}

int main()

{

const int size = 8;

default_random_engine e;

uniform_int_distribution u(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;

}


please help me i have to submit this homework today before5pm

Answer & Explanation Solved by verified expert
3.7 Ratings (536 Votes)
function void bubblesortint a int size int temp for int i size1 i 0 i for int j 0 j i j ifajaj1 tempaj    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