Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please help me Solve the question on the c ++ program and I hope that you send m

ID: 2316450 • Letter: P

Question

Please help me Solve the question on the c ++ program and I hope that you send me the file on zidane_cristiano_2010@hotmail.com please
Exercise #1 : Bubble Sortin Write a program that calls the functions int input(float [ ], void Bubble(int, int []), and void print(int, float to sort the elements of an array ascendingly using the bubble sort algorithm Sample input /output: nter how many elements in the array : 10 nter le values: 3 7 4 9 7 11 15 10 7 8 array before sorting: 3 7 4 9 7 11 15 10 7 array after sorting: 3 4777 89 1 11 15 Example. Sort (5,1, 12,-5, 16) using bubble sort. 310[12] E5] [16] unsorted 5 1 12 551, swap 1 5 12 5 6 12> -5, swap 5 112-5 16 21-516 5> 1, swap 5 12 5 16 12 -5 12> -5, Swap 5 512 16 16, ok 12

Explanation / Answer

what i have tried doing is sending the int pointer from the main function to the input function and taken the size there and tried allocating memory in the input function

#include<iostream>

int input(int array[])

{

using namespace std;

cout<<"Enter size: ";

int n;

cin>>n;

cout<<"Enter "<<n<<" values: ";

array=(int *)malloc(n*sizeof(int));

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

cin>>array[i];

return n;

}

void print(int n,int array[])

{

using namespace std;

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

cout<<" "<<array[i];

}

void Bubble(int n,int array[])

{

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

{

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

{

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

{

int t=array[j];

array[j]=array[j+1];

array[j+1]=t;

}

}

}

}

int main()

{

using namespace std;

int *array;

int n=input(array);

cout<<"Before sorting: ";

print(n,array);

Bubble(n,array);

cout<<"After sorting: "

print(n,array);

return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote