Ticker

6/recent/ticker-posts

Header Ads Widget

program to sort an array

Program to sort an array






Quicksort Describe the recursive system Quick.java that separates the array of same objects by by using, as the subroutine, the partitioning formula described in the previous exercise: Firstly, take a random element v as the partitioning element. Next, divide this array into the left sub-array containing all components not as much as V, followed by the middle sub-array containing all components equal to V, followed by the good sub-array containing all elements greater than v. Finally, Recursively take the left and just sub-arrays.



We repeat the whole process until the display is completely sorted out. At any point in time, if you take to visualize the sorting process, you know that this display is composed of two internal arrays. One separated and one unsorted. This sorted display, on the hand, is initially only the first component that we arbitrarily set as the minValue. This unsorted arrangement, on this hand, is what we call the `` left array '' i.e. This list of figures we want to analyze with minValue for each iteration. The machine can begin by saying line 1, so going from top to bottom and from left to right, It can go to line 3 and realize that from line 3 to line 23 is the use definition so it can go to line 25 where we declare the sortedList variable and assign it a value. In the time the expert recognizes that the amount it must assign to the sortedList quantity is the returned amount of the use sortList () declared on row it can invoke the function sortList () , Give it unorderedList as an argument and can accomplish what the procedure tells him to do.

Q) Write a program to sort an array?



sol)

#include<iostream>
using namespace std;

void quicksort(int arr[],int si,int ei){
    int c,i,j,temp;

     if(si < ei){
         c = si;
         i = si;
         j = ei;

         while(i < j){
             while(arr[i] <= arr[c] && i < ei)
                 i++;
             while(arr[j] > arr[c])
                 j--;
             if(i <j){
                  temp = arr[i];
                  arr[i] = arr[j];
                  arr[j] = temp;
             }
         }

         temp = arr[c];
         arr[c] = arr[j];
         arr[j] = temp;
         quicksort(arr,si,j-1);
         quicksort(arr,j+1,ei);
    }
}
int main()
{
    int s=7,n=0;

int arr[]={9,4,5,6,7,3,8};




quicksort(arr,0,s-1);
n=0;
while(n<s)
{
cout<<arr[n]<<" ";
n++;
}
}




Other related post:-

Shutdown someone pc using notepad trick
Let window speak to you
Create quiz game using notepad
Program to check planidrome
Find factorial using program
Program to check leap year
Program to sort an array
Program to multiply two matrixes
Program to find root of quadratic equations
Array coding interview questions
Program creating basic calculator
Program to convert Fahrenheit to Celsius or Celsius to Fahrenheit
Program to implement distance formula


Top featured feeds
Top pattern problems
Array coding interview questions

Post a Comment

0 Comments