Advertisement
Guest User

Untitled

a guest
Jan 15th, 2020
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4.  
  5. typedef struct Node
  6. {
  7. int data;
  8.  
  9. struct Node *next;
  10. struct Node *prev;
  11. }Node_t;
  12.  
  13.  
  14. Node_t *next = NULL;
  15. Node_t *prev = NULL;
  16.  
  17. Node_t *root = NULL;
  18. Node_t *tail = NULL;
  19.  
  20.  
  21. void push_front(int data) // v nachalo
  22. {
  23. Node_t * temp = NULL;
  24. temp = (Node_t *)malloc(sizeof(Node_t));
  25. temp->data = data;
  26. temp->next = NULL;
  27. }
  28.  
  29.  
  30. void push(Node_t * head, int data) // в конец
  31. {
  32. Node_t * current = head;
  33. while (current->next != NULL)
  34. {
  35. current = current->next;
  36. }
  37.  
  38. current->next = (Node_t *)malloc(sizeof(Node_t));
  39. current->next->data = data;
  40. current->next->next = NULL;
  41. }
  42.  
  43. void printList()
  44. {
  45. Node_t *temp = root;
  46. while (temp != NULL)
  47. {
  48. printf("%d", temp->data);
  49. temp = temp->next;
  50. }
  51. printf('\n');
  52. }
  53.  
  54.  
  55. int main()
  56. {
  57. push_front(110);
  58. push_front(20);
  59. push_front(330);
  60. push_front(41);
  61. push_front(40);
  62. push_front(56);
  63.  
  64. printList();
  65.  
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement