From b893041e478fe546612056f6a31f29bf7634f50b Mon Sep 17 00:00:00 2001 From: Mehdi ALAOUI Date: Fri, 7 Apr 2017 04:37:52 +0100 Subject: [PATCH] Optimizing code and renaming variables --- LongestSubSequence.c | 75 ++++++++++++++------------------------------ 1 file changed, 23 insertions(+), 52 deletions(-) diff --git a/LongestSubSequence.c b/LongestSubSequence.c index bf2e7e54..6f5cf8e8 100644 --- a/LongestSubSequence.c +++ b/LongestSubSequence.c @@ -1,33 +1,6 @@ #include #include -int* longestSubsequence(int* ARRAY, int LENGTH, int**RESULT,int* leRESULT_LENGTH){ - if(LENGTH<=1){ - *RESULT=ARRAY; - *leRESULT_LENGTH=LENGTH; - - } - else{ - int PIVOT=ARRAY[0],n; - int* LongestSub=NULL; - longestSubsequence(ARRAY+1,LENGTH-1,&LongestSub,&n); - if (PIVOT<=LongestSub[0]){ - int *newArray=(int *)realloc(NULL,(n+1)*sizeof(int)); - int i; - newArray[0]=PIVOT; - for(i=1;imaxi_length){ - - maxi_length=LS_RESULT_length+1; - maxi=(int*)realloc(maxi,(maxi_length)*sizeof(int)); - maxi[0]=PIVOT; - for(i=1;iLONGEST_SUB_LENGTH){ + + LONGEST_SUB_LENGTH=TEMPORARY_ARRAY_LENGTH+1; + LONGEST_SUB=(int*)realloc(LONGEST_SUB,(LONGEST_SUB_LENGTH)*sizeof(int)); + LONGEST_SUB[0]=PIVOT; + for(i=1;i