Advertisement
Guest User

help.c

a guest
Mar 21st, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.68 KB | None | 0 0
  1. #include <stdio.h>
  2. #include<stdlib.h>
  3. #pragma warning (disable:4996)
  4. #include <string.h>
  5. typedef struct id
  6. {
  7.     char fullName[20];
  8.     char igUserName[20];
  9.     char birthday[12];
  10. }personal;
  11. typedef struct no {
  12.     personal key;
  13.     struct no *next;
  14.     struct no *perv;
  15. }node;
  16. typedef struct List {
  17.     node *head;
  18. }list;
  19. node * createNude(personal data)
  20. {
  21.     node *temp = (node*)malloc(sizeof(node));
  22.     temp->key = data;
  23.     temp->next = NULL;
  24.     temp->perv = NULL;
  25.     return temp;
  26. }
  27. list * createList()
  28. {
  29.     list *temp = (list*)malloc(sizeof(list));
  30.     temp->head = NULL;
  31.     return temp;
  32. }
  33. void insertToList(list *list1, node *pervNode, node *newNode)
  34. {
  35.     if (list1->head != NULL)
  36.     {
  37.         if (pervNode == NULL)
  38.         {
  39.             list1->head->next = newNode;
  40.             newNode->next = list1->head;
  41.             newNode->perv = NULL;
  42.             list1->head = newNode;
  43.         }
  44.         else
  45.         {
  46.             newNode->perv = pervNode;
  47.             newNode->next = pervNode->next;
  48.             pervNode->next = newNode;
  49.             if (newNode->next != NULL)
  50.                 newNode->next->perv = newNode;
  51.  
  52.         }
  53.     }
  54.     else
  55.         list1->head = newNode;
  56. }
  57. void removeFromList(list * list, node * node_to_remove)
  58. {
  59.     node *  prev_node;
  60.     node *  next_node;
  61.  
  62.     if (list->head != NULL)
  63.     {
  64.  
  65.         if (node_to_remove == list->head)
  66.         {
  67.             list->head = list->head->next;
  68.         }
  69.         else
  70.         {
  71.             prev_node = node_to_remove->perv;
  72.             next_node = node_to_remove->next;
  73.  
  74.             prev_node->next = next_node;
  75.             if (next_node != NULL)
  76.             {
  77.                 next_node->perv = prev_node;
  78.             }
  79.  
  80.         }
  81.         free(node_to_remove);
  82.     }
  83. }
  84. void printStruct(personal  *pr)
  85. {
  86.     printf("Name: %s.\n",pr->fullName);
  87.     printf("Birthday: %s\n", pr->birthday);
  88.     printf("Instagram user name:%s\n", pr->igUserName);
  89. }
  90. void print_list(node * head)
  91. {
  92.     int i = 1;
  93.     personal *printg;
  94.     printf("The list: \n");
  95.     while (head != NULL)
  96.     {
  97.         printf("Number %d: ", i);
  98.         printg = &(head->key);
  99.         printStruct(printg);
  100.         head = head->next;
  101.         i++;
  102.     }
  103.     printf("That's it for now\n");
  104.  
  105. }
  106. void insertToStruct(personal *stru, char birth[], char name[], char ig[])
  107. {
  108.     strcpy(stru->birthday, birth);
  109.     strcpy(stru->fullName, name);
  110.     strcpy(stru->igUserName, ig);
  111. }
  112. void main()
  113. {
  114.     char birth1[] = "17.05.1995",birth2[]="01.08.1988";
  115.     char fullName1[] = "Adina payaya", fullName2[] = "Stephanie fran";
  116.     char igUserName1[] = "adpaya", igUserName2[] = "stefran";
  117.     list *listOfAll = createList();
  118.     personal *first, *second;
  119.     first = (personal*)malloc(sizeof(personal));
  120.     second= (personal*)malloc(sizeof(personal));
  121.     insertToStruct(first, birth1, fullName1, igUserName1);
  122.     insertToStruct(second, birth2, fullName2, igUserName2);
  123.     insertToList(listOfAll, NULL, creatNude(first));
  124.     insertToList(listOfAll, NULL, creatNude(second));
  125.     print_list(listOfAll->head);
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement