Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include<stdlib.h>
- #pragma warning (disable:4996)
- #include <string.h>
- typedef struct id
- {
- char fullName[20];
- char igUserName[20];
- char birthday[12];
- }personal;
- typedef struct no {
- personal key;
- struct no *next;
- struct no *perv;
- }node;
- typedef struct List {
- node *head;
- }list;
- node * createNude(personal data)
- {
- node *temp = (node*)malloc(sizeof(node));
- temp->key = data;
- temp->next = NULL;
- temp->perv = NULL;
- return temp;
- }
- list * createList()
- {
- list *temp = (list*)malloc(sizeof(list));
- temp->head = NULL;
- return temp;
- }
- void insertToList(list *list1, node *pervNode, node *newNode)
- {
- if (list1->head != NULL)
- {
- if (pervNode == NULL)
- {
- list1->head->next = newNode;
- newNode->next = list1->head;
- newNode->perv = NULL;
- list1->head = newNode;
- }
- else
- {
- newNode->perv = pervNode;
- newNode->next = pervNode->next;
- pervNode->next = newNode;
- if (newNode->next != NULL)
- newNode->next->perv = newNode;
- }
- }
- else
- list1->head = newNode;
- }
- void removeFromList(list * list, node * node_to_remove)
- {
- node * prev_node;
- node * next_node;
- if (list->head != NULL)
- {
- if (node_to_remove == list->head)
- {
- list->head = list->head->next;
- }
- else
- {
- prev_node = node_to_remove->perv;
- next_node = node_to_remove->next;
- prev_node->next = next_node;
- if (next_node != NULL)
- {
- next_node->perv = prev_node;
- }
- }
- free(node_to_remove);
- }
- }
- void printStruct(personal *pr)
- {
- printf("Name: %s.\n",pr->fullName);
- printf("Birthday: %s\n", pr->birthday);
- printf("Instagram user name:%s\n", pr->igUserName);
- }
- void print_list(node * head)
- {
- int i = 1;
- personal *printg;
- printf("The list: \n");
- while (head != NULL)
- {
- printf("Number %d: ", i);
- printg = &(head->key);
- printStruct(printg);
- head = head->next;
- i++;
- }
- printf("That's it for now\n");
- }
- void insertToStruct(personal *stru, char birth[], char name[], char ig[])
- {
- strcpy(stru->birthday, birth);
- strcpy(stru->fullName, name);
- strcpy(stru->igUserName, ig);
- }
- void main()
- {
- char birth1[] = "17.05.1995",birth2[]="01.08.1988";
- char fullName1[] = "Adina payaya", fullName2[] = "Stephanie fran";
- char igUserName1[] = "adpaya", igUserName2[] = "stefran";
- list *listOfAll = createList();
- personal *first, *second;
- first = (personal*)malloc(sizeof(personal));
- second= (personal*)malloc(sizeof(personal));
- insertToStruct(first, birth1, fullName1, igUserName1);
- insertToStruct(second, birth2, fullName2, igUserName2);
- insertToList(listOfAll, NULL, creatNude(first));
- insertToList(listOfAll, NULL, creatNude(second));
- print_list(listOfAll->head);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement