Compare commits
2 Commits
a0f7585ae1
...
7bf09994cf
Author | SHA1 | Date |
---|---|---|
mpabi | 7bf09994cf | |
mpabi | d9e57e8ca0 |
|
@ -1,4 +1,5 @@
|
|||
#include <stdint.h>
|
||||
#include "myfunc.h"
|
||||
|
||||
int strlen(char *s) {
|
||||
char *p = s;
|
||||
|
@ -51,12 +52,6 @@ char *alloc(int n)
|
|||
//pre processor
|
||||
#define LEN (8+2)*10
|
||||
|
||||
struct model {
|
||||
char * ptr;
|
||||
uint32_t len ;
|
||||
};
|
||||
|
||||
|
||||
//alg
|
||||
// prosta implementacji func. z bibl. std. strok przy uzyciu gpt3.5
|
||||
//
|
||||
|
|
|
@ -1,35 +1,45 @@
|
|||
#include "myfunc.h"
|
||||
#include <cstring>
|
||||
|
||||
// Lokalna deklaracja funkcji my_strlen
|
||||
static int my_strlen(const char *str) {
|
||||
int length = 0;
|
||||
while (str[length] != '\0') {
|
||||
length++;
|
||||
}
|
||||
return length;
|
||||
}
|
||||
|
||||
void count_characters(const char* alfabet, const char* slowo, uint8_t* wynik) {
|
||||
// Użycie my_strlen do obliczenia długości alfabetu
|
||||
int alfabet_length = my_strlen(alfabet);
|
||||
|
||||
for (int i = 0; i < alfabet_length; ++i) {
|
||||
wynik[i] = 0;
|
||||
}
|
||||
|
||||
for (int i = 0; i < alfabet_length; ++i) {
|
||||
for (int j = 0; slowo[j] != '\0'; ++j) {
|
||||
if (alfabet[i] == slowo[j]) {
|
||||
wynik[i]++;
|
||||
}
|
||||
int strncmp(const char* s1, const char* s2, size_t n) {
|
||||
for (size_t i = 0; i < n; i++) {
|
||||
if (s1[i] != s2[i]) {
|
||||
return (unsigned char)s1[i] - (unsigned char)s2[i];
|
||||
}
|
||||
if (s1[i] == '\0' || s2[i] == '\0') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// #include "myfunc.h"
|
||||
bool compareWords(const char* a, int lenA, const char* b, int lenB) {
|
||||
int minLen = (lenA < lenB) ? lenA : lenB;
|
||||
int cmp = strncmp(a, b, minLen);
|
||||
if (cmp == 0) {
|
||||
return lenA < lenB;
|
||||
}
|
||||
return cmp < 0;
|
||||
}
|
||||
|
||||
// const char* alfabet = "abcdefghijklmnopqrstuwxyz";
|
||||
// const char* slowo = "mpabi";
|
||||
// int wynik[26] = {0}; // Inicjalizacja tablicy wyników na 0
|
||||
void bubbleSort(model arr[], int n) {
|
||||
bool swapped;
|
||||
for (int i = 0; i < n-1; i++) {
|
||||
swapped = false;
|
||||
|
||||
// count_characters(alfabet, slowo, wynik);
|
||||
for (int j = 0; j < n-i-1; j++) {
|
||||
if (!compareWords(arr[j].ptr, arr[j].len, arr[j+1].ptr, arr[j+1].len)) {
|
||||
|
||||
// Zamiana miejscami
|
||||
model temp = arr[j];
|
||||
arr[j] = arr[j+1];
|
||||
arr[j+1] = temp;
|
||||
swapped = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!swapped) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,9 @@
|
|||
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
void count_characters(const char* alfabet, const char* slowo, uint8_t* wynik);
|
||||
struct model {
|
||||
char * ptr;
|
||||
uint32_t len ;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue