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 *link;
- } * head;
- void create(int n);
- void add(int data);
- void display();
- int main()
- {
- struct node *head;
- int n, data;
- printf("HOW MANY NODES DO YOU WANT : ");
- scanf("%d", &n);
- create(n);
- printf("Data in the list : \n");
- display();
- printf("\nenter the data you want to inseart in the end: ");
- scanf("%d", &data);
- add(data);
- printf("THE FINAL LIST ");
- display();
- return 0;
- }
- void create(int n)
- {
- head = (struct node *)malloc(sizeof(struct node));
- struct node *temp = (struct node *)malloc(sizeof(struct node));
- struct node *newnode = (struct node *)malloc(sizeof(struct node));
- int i, data;
- if (head == NULL)
- {
- printf("memory problem");
- }
- else
- {
- printf("1 NO data : ");
- scanf("%d", &data);
- head->link = NULL;
- head->data = data;
- temp = head;
- if (newnode == NULL)
- {
- printf("memory problem:");
- }
- else
- {
- for (i = 2; i <= n; i++)
- {
- printf("%d no-- data : ", i);
- scanf("%d", &data);
- newnode->data = data;
- newnode->link = NULL;
- temp->link = newnode;
- temp = temp->link;
- }
- //printf("data entry successful");
- }
- }
- }
- void add(int data)
- {
- struct node *newnode = (struct node *)malloc(sizeof(struct node));
- struct node *temp;
- newnode->data = data;
- newnode->link = NULL;
- temp = head;
- while (temp->link != NULL)
- {
- //printf("%d no data is : %d",i,temp->data);
- temp = temp->link;
- }
- temp->link = newnode;
- printf("DATA ENTWER SUCCECC\n");
- }
- void display()
- {
- struct node *temp;
- if (head == NULL)
- {
- printf("display error\n");
- }
- else
- {
- int count = 1;
- temp = head;
- while (temp!= NULL)
- {
- printf("%d no data = %d \n", count, temp->data);
- temp = temp->link;
- count++;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement