samedi 18 avril 2015

How can i fix this (is_sorted) , recursive function?


Vote count:

0




How can i fix this (is_sorted) , recursive function? Target: This function takes a string as a input parameter and returns TRUE if characters in the string are in alphabetical ascending order; returns FALSE otherwise. Characters can be lowercase or uppercase.



#include<stdio.h>
#define SIZE 50
typedef enum{FALSE,TRUE} Bool;

Bool is_sorted(const char *str);

int main(){

char arr1[SIZE]="aSTYoLPNDeSaFAE";
char arr2[SIZE]="aGjklOvz";

if(is_sorted(arr1)==TRUE){
printf("arr1 (is_sorted) Yes \n");
}
else
{
printf("arr1 (is_sorted) No \n");
}

if(is_sorted(arr2)==TRUE){
printf("arr2 (is_sorted) Yes \n");
}
else
{
printf("arr2 (is_sorted) No \n");
}

return 0;
}

Bool is_sorted(const char *str){
if(str[0]=='\0'){
return FALSE;
}
else if(strcmp(&str[0],&str[1])<0)
{
return TRUE;
}
else
{
return FALSE;
}

return is_sorted(&str[1]);
}


asked 48 secs ago







How can i fix this (is_sorted) , recursive function?

Aucun commentaire:

Enregistrer un commentaire