Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- typedef struct NODE {
- int data;
- struct NODE *next;
- }NODE;
- NODE *makeNode(int key) {
- NODE *node = (NODE *)malloc(sizeof(NODE));
- if (!node)
- return NULL;
- node->data = key;
- node->next = NULL;
- return node;
- }
- void addLast(NODE *head, NODE *temp) {
- NODE *current = head;
- while (current->next != NULL)
- current = current->next;
- current->next = temp;
- }
- void main() {
- int i, num;
- printf("Enter number for head: ");
- scanf_s("%d", &num);
- NODE *head = makeNode(num);
- for (i = 0; i < 3; i++) {
- printf("Enter Number: ");
- scanf("%d", &num);
- NODE *temp = makeNode(num);
- addLast(head, temp);
- }
- while (head)
- {
- printf("%d", head->data);
- head = head->next;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement