Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #inculde<stdlib.h>
- typedef struct mylist{
- int data;
- struct mylist *next;
- }node;
- void insert( node *s,int data)
- {
- while (s->next !=NULL)
- {
- s=s->next;
- }
- s->next=(node*)malloc(sizeof(node));
- s->next->data=data;
- s->next->next=NULL;
- }
- void display(node *s)
- {
- while(s->next!=NULL)
- {
- printf("%d\n",s->next->data);
- s=s->next;
- }
- }
- void search(node *s,int data)
- {
- int count=0;
- while(s->next!=NULL)
- {
- if(s->next->data==data){
- count++;
- }
- s=s->next;
- }
- printf("total %d results found\n",count);
- }
- void deleteNode(node *s,int data)
- {
- while(s->next!=NULL){
- if(s->next->data==data)
- {
- s->next=s->next->next;
- return 0;
- }
- s=s->next;
- }
- }
- void main()
- {
- node *first=(node*)malloc(sizeof(node));
- first->next==NULL;
- insert(first,9);
- insert(first,5);
- insert(first,11);
- insert(first,4);
- display(first);
- search(first,11);
- deleteNode(first,11);
- display(first);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement