Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Linked List
- Append()
- */
- #include <stdio.h>
- #include <stdlib.h>
- struct Node
- {
- int data;
- struct Node *next;
- };
- typedef struct Node node;
- node *head = 0;
- void append(int data)
- {
- if(head == 0)
- {
- head = (node*)malloc(sizeof(node));
- head->data = data;
- head->next = 0;
- }
- else
- {
- node *temp = (node*)malloc(sizeof(node));
- temp = head;
- while(temp->next != 0)
- {
- temp = temp->next;
- }
- node *new = (node*)malloc(sizeof(node));
- new->data = data;
- new->next = 0;
- temp->next = new;
- }
- }
- void display()
- {
- node *temp = (node*)malloc(sizeof(node));
- temp = head;
- while(temp->next != 0)
- {
- printf("%d\n", temp->data);
- temp = temp->next;
- }
- printf("%d\n", temp->data);
- }
- int main()
- {
- append(4);
- append(5);
- append(6);
- display();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement