can any one write code to find out if array is sorted in ascending order from even to odd number or not ? i will be thankful . i am new self learner of c++.
Thanks in ADVANCE

Recommended Answers

All 5 Replies

is sorted in ascending order

for(int i=1;i<sizeOfArray;++i)
{
  if (array[i]>array[i-1])
  {
    //Looking good...
  }
  else
  {
    std::cout << "Not sorted :(";
    break;
  }
}

from even to odd number or not ?

I have no idea what you mean by this.

My first language is not english i will try my best to make you guys understand what im asking
suppose int i[10]= {3,4,10,17,2,9,13,22,29,14}

now i want to check if it is sorted ascending order and also from even to odd numbers
like
from even to odd means {2,4,10,14,22,3,9,14,17,29}
every array should be checked either it is sorted from even to odd or not

Do you know how to
1) check if a value is even or odd?
2) check if one value is < or > the next number?
3) move through an array from one number to the next?

i have made the code which sort the unsorted array from even to odd but i am confused how to check the either it is sorted or not i have made the programe which can sort any array from even to odd numbers but how to check either it is sorted from even to odd or not. may be it simple task but i do not know how to do that kindly help me .

#include<stdio.h>
 
/* Function to swap *a and *b */
void swap(int *a, int *b);
 
void EvenOdd(int arr[], int size)
{
  /* Initialize left and right indexes */
  int left = 0, right = size-1;
  while(left < right)
  {
     /* Increment left index while we see 0 at left */
     while(arr[left]%2 == 0 && left < right)
        left++;
 
     /* Decrement right index while we see 1 at right */
     while(arr[right]%2 == 1 && left < right)
        right--;
 
     if(left < right)
     {
       /* Swap arr[left] and arr[right]*/
       swap(&arr[left], &arr[right]);
       left++;
       right--;
     }
  }
}    
 

void swap(int *a, int *b)
{
  int temp = *a;
  *a = *b;
  *b = temp;
}     
 

int main()
{
  int arr[] = {12, 34, 45, 9, 8, 90, 3};
  int arr_size = 7, i = 0;
 
  EvenOdd(arr, arr_size);
 
  printf("array after segregation ");
  for(i = 0; i < arr_size; i++)
    printf("%d ", arr[i]);
 
  getchar();
  return 0;
}

i have made the code which sort the unsorted array from even to odd but i am confused how to check the either it is sorted or not i have made the programe which can sort any array from even to odd numbers but how to check either it is sorted from even to odd or not. may be it simple task but i do not know how to do that kindly help me .

i tried i asked 3 questions you did not answer them if you dont answer them i dont know what you are able to do and it makes it hard to help when someone asks you a question you need to answer it not ignore it otherwise we dont want to help anymore anso when you learned english did you happen to hear about things called sentences please use them

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.