dir.main added

This commit is contained in:
ada-dmitry
2023-04-25 08:05:41 +03:00
parent 62d99ba675
commit 1f8e90cb3d
37 changed files with 1018 additions and 321 deletions
+43 -25
View File
@@ -1,16 +1,20 @@
#include "header.h"
void node_print(Node* n) {
while (n != NULL) {
void node_print(Node *n)
{
while (n != NULL)
{
printf("%s\n", n->name);
n = n->next;
}
}
Node* add_tail(Node* n, char s[]) {
if (n == NULL) {
if ((n = malloc(sizeof(Node))) == NULL) {
Node *add_tail(Node *n, char s[])
{
if (n == NULL)
{
if ((n = malloc(sizeof(Node))) == NULL)
{
printf("could not malloc\n");
exit(1);
}
@@ -19,51 +23,62 @@ Node* add_tail(Node* n, char s[]) {
memcpy(n->name, s, LEN);
return n;
}
if (!strcmp(n->name, "\0")) {
if (!strcmp(n->name, "\0"))
{
memcpy(n->name, s, LEN);
n->next = NULL;
n->prev = NULL;
return n;
}
Node* res = n;
while (n->next != NULL) n = n->next;
Node* tmp = malloc(sizeof(Node));
Node *res = n;
while (n->next != NULL){
printf("%p\n", n);
n = n->next;
}
Node *tmp = malloc(sizeof(Node));
memcpy(tmp->name, s, LEN);
tmp->prev = n;
n->next = tmp;
return res;
}
Node get(Node* node, int n) {
Node get(Node *node, int n)
{
int i;
for (i = 0; i < n; i++) {
for (i = 0; i < n; i++)
{
node = node->next;
}
return *node;
}
int len(Node* n) {
int len(Node *n)
{
int res = 0;
while (n != NULL) {
while (n != NULL)
{
res++;
n = n->next;
}
return res;
}
Node* xor_find(Node* n1, Node* n2) {
Node *xor_find(Node *n1, Node *n2)
{
int i, j, f = 0;
Node* res = NULL;
if ((res = malloc(sizeof(Node))) == NULL) {
Node *res = NULL;
if ((res = malloc(sizeof(Node))) == NULL)
{
printf("could not malloc\n");
exit(3);
}
for (i = 0; i < len(n1); i++) {
for (j = 0; j < len(n2); j++) {
if (strcmp(get(n1, i).name, get(n2, j).name) == 0) {
for (i = 0; i < len(n1); i++)
{
for (j = 0; j < len(n2); j++)
{
if (strcmp(get(n1, i).name, get(n2, j).name) == 0)
{
f = 1;
}
}
@@ -72,9 +87,12 @@ Node* xor_find(Node* n1, Node* n2) {
f = 0;
}
for (i = 0; i < len(n2); i++) {
for (j = 0; j < len(n1); j++) {
if (strcmp(get(n2, i).name, get(n1, j).name) == 0) {
for (i = 0; i < len(n2); i++)
{
for (j = 0; j < len(n1); j++)
{
if (strcmp(get(n2, i).name, get(n1, j).name) == 0)
{
f = 1;
}
}
+22 -14
View File
@@ -1,29 +1,37 @@
#include "header.h"
int main(int argc, char* argv[]) {
int main(int argc, char *argv[])
{
printf("Cto-Nibud\n");
srand(time(0));
Node* n1 = NULL;
Node* n2 = NULL;
Node* n3 = NULL;
if ((n1 = malloc(sizeof(Node))) == NULL || (n2 = malloc(sizeof(Node))) == NULL || (n3 = malloc(sizeof(Node))) == NULL) {
Node *n1 = NULL;
Node *n2 = NULL;
Node *n3 = NULL;
if ((n1 = malloc(sizeof(Node))) == NULL || (n2 = malloc(sizeof(Node))) == NULL || (n3 = malloc(sizeof(Node))) == NULL)
{
printf("could not malloc\n");
exit(2);
}
printf("Error here 1");
n1 = add_tail(n1, "bebebe");
printf("Error here 1\n");
int i;
for (i = 0; i < COUNT; i++) {
for (i = 0; i < COUNT; i++)
{
char s[LEN];
int j;
for (j = 0; j < LEN - 1; j++)
printf("sss\n");
for (j = 0; j < LEN - 1; j++)
s[j] = 'a' + rand() % 2;
s[LEN - 1] = '\0';
n1 = add_tail(n1, s);
for (j = 0; j < LEN - 1; j++)
s[j]= 'a' + rand() % 2;
n1 = add_tail(n1, s);
printf("11");
for (j = 0; j < LEN - 1; j++){
s[j] = 'a' + rand() % 2;
printf("22");
}
s[LEN - 1] = '\0';
n2 = add_tail(n2, s);
}
+9 -8
View File
@@ -6,14 +6,15 @@
#define COUNT 3
#define LEN 3
typedef struct Node {
typedef struct Node
{
char name[LEN];
struct Node* next;
struct Node* prev;
struct Node *next;
struct Node *prev;
} Node;
void node_print(Node* n);
Node* add_tail(Node* n, char s[]);
Node get(Node* node, int n);
Node* xor_find(Node* n1, Node* n2);
int len(Node* n);
void node_print(Node *n);
Node *add_tail(Node *n, char s[]);
Node get(Node *node, int n);
Node *xor_find(Node *n1, Node *n2);
int len(Node *n);
Binary file not shown.