Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.50 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3. void max_seq_pointers(int*, int*, int*, int);
  4. void max_seq(int*, int**, int**, int);
  5.  
  6. int main(){
  7.          int *start;
  8.          int startInt = 0;
  9.          int *end;
  10.          int endInt = 0;
  11.        
  12.        
  13.         int arr[10] = {11,2,33,4,55,66,66,0,22,33};
  14.         /*               /0/1/2/3/4/5/6/7/8/9/    
  15.         int arr[10] = {1,2,3,44,55,67,66,0,29,38};
  16.         */
  17.         max_seq_pointers(arr,&startInt,&endInt, 10);
  18.         max_seq(arr, &start, &end, 10);
  19.                 printf("2.\nstart: %d\n end: %d\n", *start, *end);
  20.  
  21.         return 0;
  22. }
  23.  
  24. void max_seq(int*arr, int** start, int** end, int size){
  25.  
  26.         int maxLenght = 0;
  27.         int count = 0;
  28.         int startPoint = 1, endPoint = 1;
  29.  
  30.         for(int i = 0; i < size-1; i++){
  31.                 if(*(arr+i) <= *(arr+i+1)){
  32.                         count++;
  33.  
  34.                             if(count > maxLenght){
  35.                                     startPoint += maxLenght;
  36.                                     endPoint = startPoint + count;
  37.                                 }
  38.                     }else{
  39.  
  40.                     maxLenght = count;
  41.                             count = 0;
  42.                     }
  43.          }
  44.      
  45.         *start = &startPoint;
  46.         *end = &endPoint;      
  47.  
  48. }
  49.  
  50. void max_seq_pointers(int* arr, int* start, int* end, int size){
  51.         int maxLenght = 0;
  52.         int count = 0;
  53.         *start = 1;
  54.         *end = 1;
  55.                            
  56.         for(int i = 0; i < size-1; i++){
  57.                     if(*(arr+i) <= *(arr+i+1)){
  58.                             count++;
  59.  
  60.                             if(count > maxLenght){
  61.                                     *start += maxLenght;
  62.                                     *end = *start + count;
  63.                                 }
  64.                     }else{
  65.                             maxLenght = count;
  66.                             count = 0;
  67.                     }
  68.        
  69.     }
  70.         printf("1.\nstart: %d\n end: %d\nmaxLenght: %d\n", *start, *end,(1 + *end - *start));
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement