#include <iostream>
#include <Windows.h>
#include <string>
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
using namespace std;
#define MAX 100
int main()
{
//array declaration
int arr[MAX], finalOutput[MAX] = {};
int n, i, j;
int temp;
//read total number of elements/integers to read
cout << "Enter total number of elements to read: ";
cin >> n;
//check range
if (n<0 || n>MAX)
{
cout << "Input valid range!!!" << endl;
return -1;
}
//input n elements/integers and split into two arrays
int positiveCounter = 0, negativeCounter = 0;
//int positiveInput[], negativeInput[];
vector<int> positiveInput, negativeInput;
//declare index point
int index = 0;
bool indexCheck = false;
for (i = 0; i < n; i++)
{
int input;
cout << "Enter element [" << i + 1 << "] ";
cin >> input;
arr[i] = input;
if (input > 0) { positiveInput.push_back(input); positiveCounter++; }
if (input <= 0) {
if (indexCheck == false) { index = i; indexCheck = true; }
negativeInput.push_back(input);
negativeCounter++;
}
}
//print input elements
cout << "Unsorted Array elements:" << endl;
for (i = 0; i < n; i++)
cout << arr[i] << "\t";
cout << endl;
//sorting logic
for (i = 0; i < n; i++)
{
for (j = i + 1; j < n; j++)
{
if (arr[i] > arr[j])
{
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}
sort(positiveInput.begin(), positiveInput.end());
int counter = 0;
for (i = 0; i < positiveInput.size(); i++)
{
finalOutput[i] = positiveInput[i];
counter++;
}
for (i = 0; i < negativeInput.size(); i++)
{
finalOutput[counter] = negativeInput[i];
counter++;
}
//print sorted array elements
cout << "Sorted (Ascending Order) Array elements:" << endl;
for (i = 0; i < n; i++)
cout << finalOutput[i] << "\t";
cout << endl;
cout << "Index of the first zero/negative number in the array: ";
cout << index;
return 0;
}