Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- struct node {
- int data;
- struct node *next;
- };
- typedef struct node NODE;
- struct node *head = new NODE();
- void insert() {
- struct node *temp = new struct node();
- if(head->next == NULL) {
- int x;
- printf("Enter number:\n");
- scanf("%d", &x);
- temp->data = x;
- temp->next = NULL;
- head->next = temp;
- } else {
- temp = head;
- NODE *flag = new NODE();
- while (temp->next != NULL) {
- temp = temp->next;
- }
- int x;
- printf("Enter number:\n");
- scanf("%d", &x);
- flag->data = x;
- flag->next = NULL;
- temp->next = flag;
- }
- }
- void display() {
- NODE *temp = head;
- while(temp->next != NULL) {
- printf("%d ", temp->next->data);
- temp = temp->next;
- }
- printf("\n");
- }
- int main() {
- insert();
- insert();
- display();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement