C_Practice
Functions
main.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include "definition.h"
#include "struct_process.h"
#include "linked_list.h"

Functions

int main ()
 

Function Documentation

◆ main()

int main ( )
9 {
10 
11  // Access Pointer
12  STRUCTTAG tag;
13  PSTRUCTTAG p_tag;
14  p_tag = &tag;
15 
16  // initial the structure (example)
17  struct_init(p_tag, 1, 2);
18 
19  printf("%d,%d\n",tag.memberB, p_tag->memberB);
20 
21  //Linked list
22  /* sdata has been assigned to data part of third
23  block (block pointed by third). And next pointer
24  of the third block is made NULL to indicate
25  that the linked list is terminated here.
26 
27  We have the linked list ready.
28 
29  head
30  |
31  |
32  +---+---+ +---+---+ +----+------+
33  | 1 | o----->| 2 | o-----> | 3 | NULL |
34  +---+---+ +---+---+ +----+------+
35 
36 
37  Note that only head is sufficient to represent
38  the whole list. We can traverse the complete
39  list by following next pointers. */
40 
41  P_Node head = NULL;
42  P_Node second = NULL;
43  P_Node third = NULL;
44 
45  // Allocated 3 static memories
47  linked_list_dynamic_init(&second);
49 
50  // Assign the value and link the structure
51  head->data = 1;
52  head->next = (struct Node *) second;
53 
54  second->data = 2;
55  second->next = (struct Node *) third;
56 
57  third->data = 3;
58  third->next = NULL;
59 
60  printf("Print Linked list \n");
61  printList(head);
62 
63  // Reverse the linked list
64  linked_list_reverse(&head);
65 
66  printf("Print reversed Linked list \n");
67  printList(head);
68 
69  // Push a new node
70  linked_list_push_node(&head, 3);
71  linked_list_push_node(&head, 5);
72 
73  printf("Print Linked list \n");
74  printList(head);
75 
76  printf("Print middle node \n");
77  printList_middle(head);
78 
79  return 0;
80 }
void struct_init(PSTRUCTTAG p_tag, int memberA, int memberB)
Definition: struct_process.c:9
int memberB
Definition: struct_process.h:8
Definition: struct_process.h:6
void linked_list_dynamic_init(P_Node *p_node)
Definition: linked_list.c:10
void linked_list_reverse(P_Node *head_ref)
Definition: linked_list.c:81
struct Node * next
Definition: linked_list.h:8
void printList(P_Node head)
Definition: linked_list.c:19
void printList_middle(P_Node head_ref)
Definition: linked_list.c:36
void linked_list_push_node(P_Node *head_ref, int data)
Definition: linked_list.c:57
int data
Definition: linked_list.h:7
Definition: linked_list.h:6