Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**** Headers ****************************/
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- /**** Type definitions *******************/
- /*****************************************\
- * Struct: Person
- \*****************************************/
- struct Person
- {
- char* Name;
- int Age;
- char Gender;
- };
- /*****************************************\
- * Struct: Node
- \*****************************************/
- typedef struct node
- {
- struct Person Data;
- struct node* Prev;
- struct node* Next;
- } Node;
- /**** Declarations ***********************/
- void Swap(Node* First, Node* Second)
- {
- Node* TempNode;
- TempNode = Second->Prev;
- First->Prev =
- }
- /*****************************************\
- * Function: Push
- * Purpose: Add to the linked list New Node From The Start Like Stack
- * Parameters:
- * Head - Head of the list
- * Tail - Tail of the list
- * Name - Name to put in the data of the new node
- * Age - Age to put in the data of the new node
- * Gender - Gender to put in the data of the new node
- * Return value: None.
- * Side effects: None.
- * Author: TODO: your username
- \*****************************************/
- void Push(Node* Head, char* Name, int Age, char Gender, Node** Tail)
- {
- /* Memory Allocate the New Node */
- Node* NewNode;
- if(!(NewNode = (Node *)malloc(sizeof(Node))))
- abort();
- /* Setup the New Node in the Linked List */
- NewNode->Next = Head->Next;
- if(Head->Next != NULL)
- Head->Next->Prev = NewNode;
- else
- *Tail = NewNode;
- Head->Next = NewNode;
- /* Setup the New Node's Data */
- NewNode->Data.Name = (char *)malloc(strlen(Name));
- strcpy(NewNode->Data.Name, Name);
- NewNode->Data.Age = Age;
- NewNode->Data.Gender = Gender;
- }
- /*****************************************\
- * Function: Pop
- * Purpose: Remove Node From the Tail of the list, Like Stack
- * Parameters:
- * Tail - Tail of the list
- * Return value: None.
- * Side effects: None.
- * Author: TODO: your username
- \*****************************************/
- void Pop(Node** Tail)
- {
- /* Remove The Last Node From the Linked List */
- Node* TempNode = *Tail;
- *Tail = TempNode->Prev;
- TempNode->Prev->Next = NULL;
- free(TempNode);
- }
- void Sort_List(Node** Tail, Node* Head)
- {
- }
- int main()
- {
- /* Initialize Head And Tail Of The List */
- Node* Head;
- if(!(Head = (Node *)malloc(sizeof(Node))))
- abort();
- Head->Next = NULL;
- Node* Tail = Head;
- Push(Head, "ohad", 15, 'm', &Tail);
- Push(Head, "guy", 18, 'm', &Tail);
- Push(Head, "noa", 7, 'f', &Tail);
- // Pop(&Tail);
- //Pop(&Tail);
- int i;
- Swap(Head->Next, Head->Next->Next);
- Node* Temp = Head;
- for(i = 0; i < 3; i++)
- {
- Temp = Temp->Next;
- printf("\n%s\n", Temp->Data.Name);
- }
- printf(" %d ", Tail->Data.Age);
- system("PAUSE");
- return 0;
- }
Add Comment
Please, Sign In to add comment