Main reviewed, space added between operators (+,..)

This commit is contained in:
Mehdi ALAOUI 2017-04-07 04:50:50 +01:00
parent b893041e47
commit a70400eead
2 changed files with 47 additions and 45 deletions

View File

@ -11,7 +11,7 @@ void longestSub(int* ARRAY,int ARRAY_LENGTH, int** RESULT,int* RESULT_LENGTH){ /
else{
int PIVOT = ARRAY[0];
int *LONGEST_SUB = NULL;
int LONGEST_SUB_LENGTH=0,i,j;
int i, j, LONGEST_SUB_LENGTH = 0;
int TEMPORARY_ARRAY_LENGTH = 0, *TEMPORARY_ARRAY = NULL;
for(i = 1; i < ARRAY_LENGTH; i++){
@ -33,7 +33,7 @@ void longestSub(int* ARRAY,int ARRAY_LENGTH, int** RESULT,int* RESULT_LENGTH){ /
if(LONGEST_SUB_LENGTH < TEMPORARY_ARRAY_LENGTH + 1){
LONGEST_SUB_LENGTH = TEMPORARY_ARRAY_LENGTH + 1;
LONGEST_SUB=(int*)realloc(LONGEST_SUB,(LONGEST_SUB_LENGTH)*sizeof(int));
LONGEST_SUB = (int *)realloc(LONGEST_SUB, LONGEST_SUB_LENGTH*sizeof(int));
LONGEST_SUB[0] = ARRAY[i];
for(i = 1;i < LONGEST_SUB_LENGTH; i++)
@ -57,7 +57,7 @@ void longestSub(int* ARRAY,int ARRAY_LENGTH, int** RESULT,int* RESULT_LENGTH){ /
if(TEMPORARY_ARRAY_LENGTH + 1 > LONGEST_SUB_LENGTH){
LONGEST_SUB_LENGTH = TEMPORARY_ARRAY_LENGTH + 1;
LONGEST_SUB=(int*)realloc(LONGEST_SUB,(LONGEST_SUB_LENGTH)*sizeof(int));
LONGEST_SUB = (int *)realloc(LONGEST_SUB, LONGEST_SUB_LENGTH*sizeof(int));
LONGEST_SUB[0] = PIVOT;
for(i = 1;i < LONGEST_SUB_LENGTH; i++)
LONGEST_SUB[i] = TEMPORARY_ARRAY[i-1];
@ -71,15 +71,17 @@ void longestSub(int* ARRAY,int ARRAY_LENGTH, int** RESULT,int* RESULT_LENGTH){ /
int main(){
int *example=NULL;
int n,i;
//int t[9]={10, 22, 9, 33, 21, 50, 41, 60, 80};
int t[8]={18, 2, 15, 4, 30, 0, 11, 12};
//Il y'a un problème au cas où on a un LONGEST_SUBmum au milieu
longestSub(t,8,&example,&n);
printf("longueur: %d\n",n);
for(i=0;i<n;i++)
printf("%d ",example[i]);
int EXAMPLE_LENGTH = 8;
int EXAMPLE[] = {18, 2, 15, 4, 30, 0, 11, 12};
int *RESULT = NULL;
int RESULT_LENGTH, i;
longestSub(EXAMPLE, EXAMPLE_LENGTH, &RESULT, &RESULT_LENGTH);
printf("Longest Sub Sequence length: %d and it's:\n", RESULT_LENGTH);
for(i = 0;i < RESULT_LENGTH; i++)
printf("%d ",RESULT[i]);
printf("\n");
return 0;

BIN
a.out

Binary file not shown.