| 1 | #include <stdio.h>\r |
| 2 | #include <stdlib.h>\r |
| 3 | \r |
| 4 | \r |
| 5 | struct Node \r |
| 6 | {\r |
| 7 | float f;\r |
| 8 | struct Node* next;\r |
| 9 | };\r |
| 10 | \r |
| 11 | void IterateList (struct Node* HeadList);\r |
| 12 | struct Node* makelist(struct Node** Head, struct Node** Tail);\r |
| 13 | \r |
| 14 | struct Node* makelist(struct Node** Head, struct Node** Tail)\r |
| 15 | {\r |
| 16 | struct Node* new = (struct Node *)malloc(sizeof (struct Node));\r |
| 17 | new->next = NULL;\r |
| 18 | \r |
| 19 | if (*Head == NULL)\r |
| 20 | {\r |
| 21 | *Head = new;\r |
| 22 | *Tail = *Head;\r |
| 23 | }\r |
| 24 | else\r |
| 25 | {\r |
| 26 | (*Tail)->next = new;\r |
| 27 | *Tail = new;\r |
| 28 | }\r |
| 29 | return (new);\r |
| 30 | }\r |
| 31 | void IterateList (struct Node* HeadList)\r |
| 32 | {\r |
| 33 | struct Node* current = HeadList;\r |
| 34 | \r |
| 35 | while (current != NULL)\r |
| 36 | {\r |
| 37 | printf("The float you entered is %f\n",current->f);\r |
| 38 | current = current->next;\r |
| 39 | }\r |
| 40 | }\r |
| 41 | int main(void)\r |
| 42 | {\r |
| 43 | struct Node* head = NULL;\r |
| 44 | struct Node* tail = NULL;\r |
| 45 | struct Node* curr = NULL;\r |
| 46 | int i;\r |
| 47 | \r |
| 48 | for(i=0; i < 20; i++)\r |
| 49 | {\r |
| 50 | /* create node */\r |
| 51 | curr = makelist(&head,&tail);\r |
| 52 | printf("Enter float :\n");\r |
| 53 | scanf("%f", &(curr->f));\r |
| 54 | }\r |
| 55 | \r |
| 56 | /* now iterate the list */\r |
| 57 | IterateList(head);\r |
| 58 | \r |
| 59 | return 0;\r |
| 60 | }\r |