Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- struct Node {
- int data;
- struct Node *next;
- };
- struct Node *insert(struct Node *head, int data) {
- struct Node *tmp;
- tmp = (struct Node *) malloc(sizeof(struct Node));
- tmp->data = data;
- tmp->next = head;
- head = tmp;
- return head;
- }
- void display(struct Node *head) {
- struct Node *start = head;
- while (start) {
- printf("%d ", start->data);
- start = start->next;
- }
- printf("\n");
- }
- int main() {
- int T, data;
- scanf("%d", &T);
- struct Node *head = NULL;
- while (T-- > 0) {
- scanf("%d", &data);
- head = insert(head, data);
- }
- display(head);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement