Smalti
BAN USER
Comments (4)
Reputation 10
Page:
1
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
1
of 1 vote
#include "stdafx.h"
#include <string.h>
size_t right_pos(char* p, size_t arr_len)
{
return ('1' <= *p && '9' >= *p) ? (arr_len >> 1) + (*p - '1') : (*p - 'a');
}
void swap(char* arr, size_t i, size_t j)
{
char tmp = arr[ i ];
arr[ i ] = arr[ j ];
arr[ j ] = tmp;
}
int sorter(char* arr, size_t i, size_t arr_len)
{
size_t pos = right_pos(arr + i, arr_len);
if (i != pos) swap(arr, i, pos);
else return ++i;
pos = right_pos(arr + i, arr_len);
if (pos != right_pos(arr + pos, arr_len))
return sorter(arr, pos, arr_len) + 1;
}
int _tmain(int argc, _TCHAR* argv[])
{
char arr[] = "a1b2c3d4e5f6g7";
for (size_t i = 0; i < strlen(arr); )
i = sorter(arr, i, strlen(arr));
return 0;
}
Page:
1
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
I think nothing)
- Smalti October 04, 2012