Please send code and show a screenshot of the output after code is run Please fo
ID: 3880170 • Letter: P
Question
Please send code and show a screenshot of the output after code is run Please follow all instructions If possible, please provide a screenshot(step by step) or brief summary of how to perform this task. Please use C program ECE 216 Programming Project 2 The Bubble Sort You will create a simple Bubble Sort program to sort a string of random integers or text or whatever you can punch in from the keyboard. For the input data, you will input a string of single digit ASCII characters, at least 20 of them, in some sort of random order. You aren't limited to 20. Put in 100 if you like. For the output data, you will simply print this string after it is sorted. For the process, you will sort the data in either descending order (largest value first smallest value last) or ascending order, but you can allow for both possibilities if you wish In order to sort the data, you will need to develop the algorithm for a bubble sort, then create a flow chart or pseudocode so you will understand the process, and finally code it. The bubble sort is perhaps the easiest of the sorting algorithms to write. The basic principle is to simply compare two adjacent numbers. If they are in order, then leave them alone and move to the next pair. If they are out of order, swap their positions in memory, and then move onto the next pair Here is a simple example using 5 numbers. 18496 Start: 1 pass: compare 1 to 8 out of order, swap them now have: 81496 now have: now have: now have: 2nd pass: compare 1 to 4 84196 compare 1 to 9 84916 compare 1 to 6 84961 out of order, swap them out of order, swap them out of order, swap them compare 8 to 4 compare 4 to 9 in order, no swap out of order, swap them now have: 89461 compare 4 to 6 compare 4 to 1 compare 8 to 9 out of order, swap them in order, no swap out of order, swap them now have: 89641 3rd pass: now have: 98641 compare 8 to 6 compare 6 to 4 compare 4 to1 in order, no swap in order, no swap in order, no swapExplanation / Answer
//Please see the code below:
#include<stdio.h>
char arry[100];
void bubbleSort(int count)
{
int i, j;
char temp;
for (i = 0; i < count-1; i++)
// Last i elements are already in place
for (j = 0; j < count-i-1; j++)
{
if (arry[j] < arry[j+1])
{
temp=arry[j];
arry[j]=arry[j+1];
arry[j+1]=temp;
}
}
}
int main()
{
char ch='0';
int count=0;
printf("Please enter one char at a time, press E for exit ");
while(ch!='E')
{
scanf("%c",&ch);
if(ch=='E')
break;
arry[count]=ch;
count++;
}
bubbleSort(count);
for(int i=1 ;i<=count;i++)
{
printf("%c ",arry[i-1]);
if(i%10==0)
printf(" ");
}
return 0;
}
OUTPUT:
Please enter one char at a time, press E for exit
2 8 6 7 4 9 5 1 6 7
3 4 9 5 1 2 8 1 7 4
E
9 9 8 8 7 7 7 6 6 5
5 4 4 4 3 2 2 1 1 1
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.