Compare commits
No commits in common. "7bf09994cf0e7a67d5e3c54990117dcdcda9e614" and "a0f7585ae11c960607a83c09844bf8c203308f08" have entirely different histories.
7bf09994cf
...
a0f7585ae1
|
@ -1,5 +1,4 @@
|
|||
#include <stdint.h>
|
||||
#include "myfunc.h"
|
||||
|
||||
int strlen(char *s) {
|
||||
char *p = s;
|
||||
|
@ -52,6 +51,12 @@ 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,45 +1,35 @@
|
|||
#include "myfunc.h"
|
||||
#include <cstring>
|
||||
|
||||
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];
|
||||
// Lokalna deklaracja funkcji my_strlen
|
||||
static int my_strlen(const char *str) {
|
||||
int length = 0;
|
||||
while (str[length] != '\0') {
|
||||
length++;
|
||||
}
|
||||
if (s1[i] == '\0' || s2[i] == '\0') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
return length;
|
||||
}
|
||||
|
||||
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;
|
||||
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;
|
||||
}
|
||||
|
||||
void bubbleSort(model arr[], int n) {
|
||||
bool swapped;
|
||||
for (int i = 0; i < n-1; i++) {
|
||||
swapped = false;
|
||||
|
||||
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;
|
||||
for (int i = 0; i < alfabet_length; ++i) {
|
||||
for (int j = 0; slowo[j] != '\0'; ++j) {
|
||||
if (alfabet[i] == slowo[j]) {
|
||||
wynik[i]++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!swapped) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// #include "myfunc.h"
|
||||
|
||||
// const char* alfabet = "abcdefghijklmnopqrstuwxyz";
|
||||
// const char* slowo = "mpabi";
|
||||
// int wynik[26] = {0}; // Inicjalizacja tablicy wyników na 0
|
||||
|
||||
// count_characters(alfabet, slowo, wynik);
|
||||
|
|
|
@ -3,9 +3,7 @@
|
|||
|
||||
#include <stdint.h>
|
||||
|
||||
struct model {
|
||||
char * ptr;
|
||||
uint32_t len ;
|
||||
};
|
||||
|
||||
void count_characters(const char* alfabet, const char* slowo, uint8_t* wynik);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue