hi i'm trying to tranform while loop to a recursive function to read the array from left to right and then another version from right to left but i'm just unable ! can i have some idea ?

#include<stdio.h>
#define DIM 10
int csTrie(int n, int *tab){
  int i=0;
  while(i<(n-1)&&tab[i]<=tab[i+1]){
    i++;
  }
  return i==(n-1);
}
void main(){
  int tab[DIM]={2,3,4,6,9};
  int i=0;
  printf("LOGICFOUND:%d\n", csTrie(5, tab));
}

Pseudo code

loop function (array):
   for each element in array
       if its the one you're looking for exit loop

recursive function (array):
   if the first element is the one you're looking for return it
   return recursive function(array with the first element removed)

ps you don't need to create a new array - just pass a ref to the new "first" element

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.