8 (Partition of a list)

PHOTO EMBED

Tue Dec 29 2020 11:21:13 GMT+0000 (Coordinated Universal Time)

Saved by @mahmoud hussein #c++

#include <iostream>
#include<iomanip>
#include <string>

using namespace std;

void partisons(int list[], int listSize);


int main() 
{
	const int size1 = 6;
	
	
	int list1[size1];
	for (int i = 0; i <size1 ; i++)
	{
		cin >> list1[i];
	}
	 selectionSort(list1, size1);

	
	for (int i = 0; i < size1; i++)
	{
		cout << list1[i] << " ";
	}

	
}

void partisons(int list[], int listSize)
{
    int first = 0;
    int low = first + 1;
    int high = listSize - 1;
    int pivot = list[first];

    while (high > low) {

        while (low <= high && list[low] <= pivot)
        {
            low++;
        }
        while (low <= high && list[high] > pivot)
        {
            high--;
        }
        if (high > low) {
            int temp = list[high];
            list[high] = list[low];
            list[low] = temp;
        }
    }

    while (high >= low && list[high] >= pivot) high--;

    if (high > first) {
        int temp = list[high];
        list[high] = list[first];
        list[first] = temp;
        
    }
    
	 }
	
	


content_copyCOPY

http://cpp.sh/