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* head = NULL;
- void insert(int data) {
- struct node* temp;
- temp = (struct node*)malloc(sizeof(struct node));
- temp->data = data;
- temp->next = NULL;
- if(head == NULL) {
- head = temp;
- }
- else {
- struct node* temp2;
- temp2 = head;
- while(temp2->next != NULL) {
- temp2 = temp2->next;
- }
- temp2->next = temp;
- }
- }
- void print()
- {
- struct node*temp;
- temp = head;
- while(temp != NULL) {
- printf("%d\n" , temp->data);
- temp = temp->next;
- }
- }
- int main ()
- {
- int x, i;
- scanf("%d" , &x);
- int m;
- for(i = 1; i <= x; i++) {
- scanf("%d" , &m);
- insert(m);
- }
- print();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement