How can one explain line after line what these lines of codes does and how its f
ID: 3661479 • Letter: H
Question
How can one explain line after line what these lines of codes does and how its functions. There are 22 lines we are expected to have 22 comments .Explain each line and say what it has for function. #include #define VSIZE 7 void bubbleSort(int theArray[],int rows){ int tmp; for(int times=0;timestheArray[row-1]){ tmp=theArray[row]; theArray[row]=theArray[row+1]; theArray[row+1]=tmp; } } int main(void){ int vector[VSIZE]={12,3,6,18,7,15,10}; bubbleSort(vector,VSIZE); for(int row=0;row (C language)
2) Fix this code if any so at the sorted order is[ 3] [6] [7] [10] [12] [15] [18]
Explanation / Answer
#include<stdio.h> // header file standard input output
#define VSIZE 7 // to size of the variable, it is 7
void bubbleSort(int theArray[],int rows) // bubble sort method to perform sorting, it contains two //variables the array[] and rows
{ // every method starts with curly brace
int tmp; // tmp is a temporary variable of integer data type
for(int times=0;timestheArray[row-1]) // for loop is used to perform multiple operations I.e compare //first number with other and second number ...
{ // beginning of for loop
tmp=theArray[row]; // tmp variable is temporary variable used to perform swapping of variables
theArray[row]=theArray[row+1]; // exchange values if condition true
theArray[row+1]=tmp; // swapping using third variable
printf(" sorted elements are : %d", theArray[row+1]); // printf is used to display the results
} // end of for loop
} // end of method
int main(void) // every program has main method
{ // begining of main method
int vector[VSIZE]={12,3,6,18,7,15,10}; // here vsize is defined, it is 7 I.e vector is an array variable of //size 7. It contains 7 values ( 12,3,6,18,7,15,10)
bubbleSort(vector,VSIZE); // calling of method bubbleSort
} // end of main method
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.