Skip to content

Instantly share code, notes, and snippets.

@mrnonz
Created August 19, 2015 10:09
Show Gist options
  • Save mrnonz/b2d712b76e9b40761422 to your computer and use it in GitHub Desktop.
Save mrnonz/b2d712b76e9b40761422 to your computer and use it in GitHub Desktop.
//
// main.c
// Radix_sort
//
// Created by Nontawat Numor on 8/19/2558 BE.
// Copyright (c) 2558 Nontawat Numor. All rights reserved.
//
#include <stdio.h>
void swap(int* a, int* b) {
int tempA, tempB;
tempA = *a;
tempB = *b;
*b = tempA;
*a = tempB;
}
int main(int argc, const char * argv[]) {
int Data[100] = {0}, tempData[100] = {0}, count, Max = 0, Min = 0;
int i, j, k, len = 0 , tempi;
printf("Enter size of your array :: ");
scanf("%d",&count);
for (i=0; i<count; i++) {
scanf("%d", &Data[i]);
tempData[i] = Data[i];
if (i==0) {
Max = Data[i];
Min = Data[i];
} else {
if (Max < Data[i]) {
Max = Data[i];
}
if (Min > Data[i]) {
Min = Data[i];
}
}
}
while (Max != 0 || Min != 0) {
Max /= 10;
Min /= 10;
len++;
}
for (k=0; k<len; k++) {
for (i=0; i<count; i++) {
Min = Data[i] % 10;
tempi = i;
for (j=i+1; j<count; j++) {
if (Min > Data[j] % 10) {
Min = Data[j] % 10;
tempi = j;
}
}
swap(&tempData[i], &tempData[tempi]);
swap(&Data[i], &Data[tempi]);
for (i=0; i<count; i++) {
Data[i] /= 10;
}
}
}
for (i=0; i<count; i++) {
printf("%d ",tempData[i]);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment