Skip to content

Instantly share code, notes, and snippets.

@stargazing-dino
Created July 18, 2022 19:34
Show Gist options
  • Save stargazing-dino/2167148233e939b999ed72b62324aa0d to your computer and use it in GitHub Desktop.
Save stargazing-dino/2167148233e939b999ed72b62324aa0d to your computer and use it in GitHub Desktop.
sort comparison
uint16_t i = 0, j = 0;
uint32_t tmp = 0;
uint32_t sum = 0;
for (i = 0; i < size - 1; i++)
{
for (j = 0; j < size - 1; j++) // does not use i therefore probably touching the same data in every loop
{
if (dat[j] > dat[j + 1])
{
tmp = dat[j];
dat[j] = dat[j + 1];
dat[j + 1] = tmp;
}
}
}
// From https://www.tutorialspoint.com/learn_c_by_examples/median_program_in_c.htm
#include <stdio.h>
void swap(int *p,int *q) {
int t;
t=*p;
*p=*q;
*q=t;
}
void sort(int a[],int n) {
int i,j,temp;
for(i = 0;i < n-1;i++) {
for(j = 0;j < n-i-1;j++) { // This uses i in some way
if(a[j] > a[j+1])
swap(&a[j],&a[j+1]);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment