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

write a C++ program (in classes) that takes the numbers 38, 5, 2, 70, 39, 14, 27

ID: 3684661 • Letter: W

Question

write a C++ program (in classes) that takes the numbers 38, 5, 2, 70, 39, 14, 27, 3, and 100 and does the following: asks the user to select the preferred the data structure (linked list) asks the user to select the preferred algorithm (search or sort) asks the user to select the preferred search or sorting algorithm, depending on the previous selection sorting algorithms: selection sort, bubble sort, merge sort, quicksort, insertion sort searching algorithms: selection search (linear search), binary search carries out the user-selected searching or sorting algorithm and asks the user if they would like to continue - the program continues executing until the user indicates that they wish to exit the program

Explanation / Answer

C++ program for sorting a data structure is given below:

#include<iostream>

using namespace std;

void bubbleSort(int* a, int n);

int main()
{
    int array[50],len,i;
    cout<<"Enter array size: ";
    cin>>len;
    cout<<"Enter array element: ";
  
    for(i=0;i<len;++i)
        cin>>array[i];
      
    cout<<"Array before bubble Sorting :";
    for(i=0;i<len;++i)
        cout<<" "<<array[i];
  
    cout<<endl;
      
   bubbleSort(array, len);
      
    return 0;
}

void bubbleSort(int* a, int n)
{
   int tempVal, i;
  
   for( i=1;i<n;++i)
    {
        for(int j=0;j<(n-i);++j)
            if(a[j]>a[j+1])
            {
                tempVal=a[j];
                a[j]=a[j+1];
                a[j+1]=tempVal;
            }
    }
  
    cout<<"Array after bubble sorting:";
    for(i=0;i<n;++i)
        cout<<" "<<a[i];
  
}