42 lines
722 B
C++
42 lines
722 B
C++
#include <stdio.h>
|
|
|
|
int strlen(const char *s) {
|
|
int len = 0;
|
|
while (*s != '\0') {
|
|
len++;
|
|
s++;
|
|
}
|
|
return len;
|
|
}
|
|
|
|
void strcpy(char *dest, const char *src) {
|
|
while (*src != '\0') {
|
|
*dest = *src;
|
|
dest++;
|
|
src++;
|
|
}
|
|
*dest = '\0';
|
|
}
|
|
|
|
void bubble_sort(char *str, int len) {
|
|
for (int i = 0; i < len - 1; i++) {
|
|
for (int j = 0; j < len - i - 1; j++) {
|
|
if (str[j] > str[j + 1]) {
|
|
char temp = str[j];
|
|
str[j] = str[j + 1];
|
|
str[j + 1] = temp;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
int main() {
|
|
char word[] = "Fabian";
|
|
int length = strlen(word);
|
|
|
|
bubble_sort(word, length);
|
|
|
|
return 0;
|
|
}
|
|
|