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;
- }*node,*temp;
- struct Head
- {
- int count;
- struct Node *p;
- }*head;
- void createNode()
- {
- node=(struct Node*)malloc(sizeof(struct Node));
- scanf("%d", &node->data);
- node->next=NULL;
- node->next=head->p;
- head->p=node;
- head->count++;
- }
- void add_last()
- {
- temp=head->p;
- while(temp->next!=NULL)
- {
- temp=temp->next;
- }
- node=(struct Node*)malloc(sizeof(struct Node));
- scanf("%d", &node->data);
- node->next=NULL;
- temp->next=node;
- head->count++;
- }
- void delate_first()
- {
- temp=head->p;
- head->p=temp->next;
- free(temp);
- head->count--;
- }
- void show()
- { int i;
- temp=head->p;
- for(i=1;i<=head->count;i++)
- {
- printf("\n %d ", temp->data);
- temp=temp->next;
- }
- }
- int main()
- {
- int a,i,n,m;
- head=(struct Head*)malloc(sizeof(struct Head));
- head->count=0;
- head->p=NULL;
- printf("where you want to add node?\n");
- printf("At first or at last");
- printf("press 1 for add first & press 2 for add last");
- scanf("%d",&a);
- if(a==1)
- {
- printf("how many node you want to create?");
- scanf("%d",&n);
- for(m=1;m<=n;m++)
- {
- createNode();
- }
- show();
- }
- if(a==2)
- {
- printf("at first create a node");
- createNode();
- add_last();
- show();
- }
- delate_first();
- }
Add Comment
Please, Sign In to add comment