diff --git a/PL/Lessons/L28.03 - Dinamic Structure/func.c b/PL/Lessons/L28.03 - Dinamic Structure/func.c new file mode 100644 index 0000000..9c2144c --- /dev/null +++ b/PL/Lessons/L28.03 - Dinamic Structure/func.c @@ -0,0 +1,84 @@ +#include +#include +#include +#include "header.h" + +void pr(node *tmp){ + int i; + if(tmp == NULL){printf("[%p]\n", tmp); return;} + while(tmp){ + printf("[%14p]<-[%14p]->[%14p] ", tmp->prev, tmp, tmp->next); + printf("data: [%4ld] s[" , tmp->data); + for(i=0;is[i]); + printf("]\n"); + tmp = tmp->next; + } + printf("---------------------\n"); +} + +node *add_head(node *head, int hh){ + node *tmp=NULL; + int i; + if((tmp=malloc(sizeof(node)))==NULL){ + perror("malloc: NULL"); + exit(2); + } + tmp->prev=NULL; + tmp->data=hh; + for(i=0;is[i]=((char)(65+rand()%25)); + if(head==NULL) tmp->next=NULL; + else{ + tmp->next=head; + head->prev=tmp; + } + return tmp; +} + +node *add_tail(node *head, int hh){ + node *tmp=NULL; + node *t = NULL; + int i; + if((tmp=malloc(sizeof(node)))==NULL){ + perror("malloc: NULL"); + exit(3); + } + + tmp->data=hh; + for(i=0;is[i]=((char)(65+rand()%25)); + tmp->next=NULL; + if(head==NULL) tmp->prev=NULL; + else{ + t = head; + while(t->next!=NULL) t = t->next; + t->next=tmp; + tmp->prev=head; + } + return head; +} + +node *del_head(node *head){ + node *tmp = head; + if(head==NULL) return NULL; + if(head -> next == NULL){ + free(head); + return NULL; + } + head = head->next; + head -> prev = NULL; + free(tmp); + return head; +} + +node *del_tail(node *list){ + node *tail = NULL; + if(list==NULL) return NULL; + if(list -> next == NULL){ + free(list); + return NULL; + } + tail = list; + while(tail->next->next) tail = tail->next; + free(tail->next); + tail -> next=NULL; + return list; +} \ No newline at end of file diff --git a/PL/Lessons/L28.03 - Dinamic Structure/header.h b/PL/Lessons/L28.03 - Dinamic Structure/header.h new file mode 100644 index 0000000..b595927 --- /dev/null +++ b/PL/Lessons/L28.03 - Dinamic Structure/header.h @@ -0,0 +1,19 @@ +#define COUN 40 + + +typedef struct Node { + long int data; + struct Node *next; + struct Node *prev; + char s[COUN]; +} node; + +void pr(node *tmp); +node *add_head(node *head, int hh); +node *add_tail(node *head, int hh); +node *del_head(node *head); +node *del_tail(node *list); +// node *sort(node *head); +// int lenghth(node *list); +// void writefile(const char *path, node *head); +// node *readfile(const char *path); diff --git a/PL/Lessons/L28.03 - Dinamic Structure/main.c b/PL/Lessons/L28.03 - Dinamic Structure/main.c new file mode 100644 index 0000000..bb2af85 --- /dev/null +++ b/PL/Lessons/L28.03 - Dinamic Structure/main.c @@ -0,0 +1,22 @@ +#include +#include +#include +#include "header.h" +#include + +int main(int args, char *argv[]){ + node *head=NULL; + int r; + srand(time(NULL)); + + while((r=(rand()%100))<90) head = add_head(head,r); + pr(head); + head = del_head(head); + pr(head); + + head = add_tail(head, 5); + pr(head); + + head = del_tail(head); + pr(head); +} \ No newline at end of file diff --git a/PL/Lessons/L28.03 - Dinamic Structure/mainc.exe b/PL/Lessons/L28.03 - Dinamic Structure/mainc.exe new file mode 100644 index 0000000..fb359a4 Binary files /dev/null and b/PL/Lessons/L28.03 - Dinamic Structure/mainc.exe differ diff --git a/PL/SortVibor.py b/Programming/SortVibor.py similarity index 100% rename from PL/SortVibor.py rename to Programming/SortVibor.py