Hi guys , I would you to help me to solve this problem

First , user need to input 10 numbers

Ex : 85 11 36 174 112 24 73 52 183 149

Next , user need to input the initial number . This initial number will determine whether the program is ascending or descending order

Ex : Initial number 50 based on above input
It means that services is carried out on track requests 50 and above

50 up to 199 ( 199 is the last compulsory number we need to reach)

After reaching 199 it will go directly to 0 ( 0 is the first compulsory number we need tor reach)

The sorted number will be as follow
Hence we will be going from 50 up to 199
then we will be going down from 199 to 0 .
From 0 to the numbers before initial (50) 11 , 24 ,36

We need also to calculate the travel track

The output will be as follow

Initial Arm position: 50 Direction: OUT

Start Finished Track Travelled
50 52 2
52 73 21
73 85 .
85 112 .
112 149 .
149 174 .
174 183 .
183 199 .
199 0 ..
0 11 nn
11 24 nn
24 36 nn
Total Track Travelled : ..

I only manage to this code

#include <iostream> 
using namespace std; 
int main(){ 
int a1, a2, a3, a4,a5,a6,a7,a8,a9,a10,it; 

cout<<"Enter 10 input "; 
cin>>a1>> a2>>a3>> a4>>a5>>a6>>a7>>a8>>a9>>a10; 
cout<<"Initial number "; 
cin it; 

for (int i=0;i<10;i++) 
{ 
if (a1>a2) 
int temp 
} 
}

11 24 36 52 73 85 112 149 174 183

If I understand you corectly this should work.

#include <iostream>
using namespace std;

void BubbleSort(int *array, int from, int size, bool decreasing){
    bool bDone = false;
    while (!bDone)
    {
        bDone = true;
        for (int i = from; i != size - 1; ++i)
        {

            if (decreasing){
                if ( array[i] > array[i + 1] )
                {
                    int tmp = array[i];
                    array[i] = array[i+1];
                    array[i+1] = tmp;

                    bDone = false;
                }
            }else{
                if ( array[i] < array[i + 1] )
                {
                    int tmp = array[i];
                    array[i] = array[i+1];
                    array[i+1] = tmp;

                    bDone = false;
                }
            }
        }
    }
}

int main(){
    int n;
    cout << "Enter n value (min 5, max 15): "; cin >> n;
    cout << endl;

    if (n<5)
        n = 5;
    if (n>15)
        n = 15;

    int* field = new int[n];

    for (int i = 0; i<n; i++)
        cin >> field[i];

    int index;
    cout << "Enter index (min 1, max " << n << "): "; cin >> index;
    cout << endl;

    if (index<1)
        index = 1;
    if (index>n)
        index = n-1;

    BubbleSort(field, 0, index, true);
    BubbleSort(field, index, n, false);

    for (int i = 0; i<n; i++)
        cout << field[i] << ", ";
}

delete[] field

Edited 2 Years Ago by Kristian_2: fixed some errors with specific input.

sorry but the ouput automatically execute . moreover , it is not complete yet

This question has already been answered. Start a new discussion instead.