Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- const int MAX_SIZE = 1000;
- bool isSorted(int array[], int n, int i)
- {
- if (i == n - 2)
- {
- if (array[i] > array[i+1])
- {
- return false;
- }
- }
- else
- {
- if (array[i] > array[i + 1])
- {
- return false;
- }
- isSorted(array, n, i + 1);
- }
- return true;
- }
- void printArray(int array[], int n, int i)
- {
- if (i == n - 1)
- {
- cout << array[i];
- }
- else
- {
- cout << array[i];
- isSorted(array, n, i + 1);
- }
- }
- void loopThroughArray(int array[], int newArray[], int n, int i, int counter)
- {
- if (counter == i-1)
- newArray[i] = array[i];
- if (i == n - 1)
- {
- newArray[i] = array[i];
- }
- else
- {
- if (newArray[i] > newArray[i - 1] )
- counter++;
- loopThroughArray(array, newArray, n, i + 1, counter);
- }
- }
- void insertInSorted(int array[], int newArray[],int n, int i)
- {
- if (i == 0)
- newArray[i] = array[i];
- if (i == 1)
- {
- if (newArray[i] > newArray[i-1])
- {
- newArray[i] = array[i];
- }
- else {
- int temp;
- temp = newArray[i - 1];
- newArray[i - 1] = newArray[i];
- newArray[i] = temp;
- }
- }
- else if (i == n )
- return;
- else
- {
- loopThroughArray(array, newArray, n, 0,0);
- }
- insertInSorted(array, newArray, n, i + 1);
- }
- int main()
- {
- int n;
- int array[MAX_SIZE];
- int newArray[MAX_SIZE];
- cout << "Enter your N: ";
- cin >> n;
- for (size_t i = 0; i < n; i++)
- {
- cin >> array[i];
- }
- insertInSorted(array, newArray, n, 0);
- isSorted(newArray, n, 0);
- printArray(array, n, 0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement