Posted By

porker912 on 02/10/16


Tagged


Versions (?)

Sorting Snippet.


 / Published in: C
 

pls hlp

  1. #include <stdlib.h>
  2. #include <stdio.h>
  3.  
  4. int main() {
  5.  
  6. int arrayLength;
  7. scanf("\n%d", &arrayLength);
  8.  
  9. int *numberCount=malloc(arrayLength*sizeof(int));
  10.  
  11. int i;
  12. for(i=0; i<arrayLength; i++) {
  13. scanf("\n%d", &numberCount[i]);
  14. }
  15.  
  16. int countOfComparators=(arrayLength*arrayLength-1)/2;
  17.  
  18. int temp;
  19. int comparatorIterations=0;
  20.  
  21. for(comparatorIterations<arrayLength; comparatorIterations++;) {
  22.  
  23. if(numberCount[comparatorIterations] > numberCount[comparatorIterations+1]) {
  24.  
  25. temp=numberCount[comparatorIterations+1];
  26.  
  27. numberCount[comparatorIterations+1]=numberCount[comparatorIterations];
  28. numberCount[comparatorIterations]=temp;
  29. }
  30. }
  31.  
  32.  
  33. int loopNum;
  34. for(loopNum=0; loopNum<arrayLength; loopNum++) {
  35. printf("\n%d", numberCount[loopNum]);
  36. }
  37.  
  38.  
  39.  
  40. return 0;
  41. }

Report this snippet  

You need to login to post a comment.