Guest User

Untitled

a guest
Aug 10th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.09 KB | None | 0 0
  1. /**** Headers ****************************/
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5.  
  6. /**** Type definitions *******************/
  7. /*****************************************\
  8. * Struct: Person
  9. \*****************************************/
  10. struct Person
  11. {
  12. char* Name;
  13. int Age;
  14. char Gender;
  15. };
  16.  
  17. /*****************************************\
  18. * Struct: Node
  19. \*****************************************/
  20. typedef struct node
  21. {
  22. struct Person Data;
  23. struct node* Prev;
  24. struct node* Next;
  25. } Node;
  26.  
  27.  
  28. /**** Declarations ***********************/
  29.  
  30.  
  31. void Swap(Node* First, Node* Second)
  32. {
  33. Node* TempNode;
  34. TempNode = Second->Prev;
  35. First->Prev =
  36. }
  37.  
  38. /*****************************************\
  39. * Function: Push
  40. * Purpose: Add to the linked list New Node From The Start Like Stack
  41. * Parameters:
  42. * Head - Head of the list
  43. * Tail - Tail of the list
  44. * Name - Name to put in the data of the new node
  45. * Age - Age to put in the data of the new node
  46. * Gender - Gender to put in the data of the new node
  47. * Return value: None.
  48. * Side effects: None.
  49. * Author: TODO: your username
  50. \*****************************************/
  51. void Push(Node* Head, char* Name, int Age, char Gender, Node** Tail)
  52. {
  53. /* Memory Allocate the New Node */
  54. Node* NewNode;
  55. if(!(NewNode = (Node *)malloc(sizeof(Node))))
  56. abort();
  57. /* Setup the New Node in the Linked List */
  58. NewNode->Next = Head->Next;
  59. if(Head->Next != NULL)
  60. Head->Next->Prev = NewNode;
  61. else
  62. *Tail = NewNode;
  63. Head->Next = NewNode;
  64. /* Setup the New Node's Data */
  65. NewNode->Data.Name = (char *)malloc(strlen(Name));
  66. strcpy(NewNode->Data.Name, Name);
  67. NewNode->Data.Age = Age;
  68. NewNode->Data.Gender = Gender;
  69. }
  70.  
  71. /*****************************************\
  72. * Function: Pop
  73. * Purpose: Remove Node From the Tail of the list, Like Stack
  74. * Parameters:
  75. * Tail - Tail of the list
  76. * Return value: None.
  77. * Side effects: None.
  78. * Author: TODO: your username
  79. \*****************************************/
  80. void Pop(Node** Tail)
  81. {
  82. /* Remove The Last Node From the Linked List */
  83. Node* TempNode = *Tail;
  84. *Tail = TempNode->Prev;
  85. TempNode->Prev->Next = NULL;
  86. free(TempNode);
  87. }
  88.  
  89. void Sort_List(Node** Tail, Node* Head)
  90. {
  91.  
  92. }
  93.  
  94. int main()
  95. {
  96. /* Initialize Head And Tail Of The List */
  97. Node* Head;
  98. if(!(Head = (Node *)malloc(sizeof(Node))))
  99. abort();
  100. Head->Next = NULL;
  101. Node* Tail = Head;
  102.  
  103. Push(Head, "ohad", 15, 'm', &Tail);
  104. Push(Head, "guy", 18, 'm', &Tail);
  105. Push(Head, "noa", 7, 'f', &Tail);
  106.  
  107. // Pop(&Tail);
  108. //Pop(&Tail);
  109. int i;
  110. Swap(Head->Next, Head->Next->Next);
  111. Node* Temp = Head;
  112. for(i = 0; i < 3; i++)
  113. {
  114. Temp = Temp->Next;
  115. printf("\n%s\n", Temp->Data.Name);
  116. }
  117. printf(" %d ", Tail->Data.Age);
  118.  
  119. system("PAUSE");
  120. return 0;
  121. }
Add Comment
Please, Sign In to add comment