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;
- };
- struct node *Head=NULL;
- struct node *Tail=NULL;
- void last(int value1){
- struct node *Node=(struct node*)malloc(sizeof(struct node));
- Node->data=value1;
- Node->link=NULL;
- if(Head==NULL){
- Head=Node;
- Tail=Node;
- }else{
- Tail->link=Node;
- Tail=Node;
- }
- }
- void first(int value2){
- struct node *Node1=(struct node*)malloc(sizeof(struct node));
- Node1->data=value2;
- Node1->link=NULL;
- if(Head==NULL){
- Head=Node1;
- Tail=Node1;
- }else{
- Node1->link=Head;
- Head=Node1;
- }
- }
- void search(int value3){
- struct node *src=Head;
- int count=0;
- while(src->link !=NULL){
- if(src->data==value3){
- count++;
- break;
- }
- src=src->link;
- }
- if(count==0){
- printf("Not found\n");
- }else{
- printf("found\n");
- }
- }
- void display(){
- struct node *ptr=Head;
- while(ptr->link!=NULL){
- printf("%d ",ptr->data);
- ptr=ptr->link;
- }
- }
- main(){
- last(10);
- last(20);
- display();
- search(11);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement