Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///Link list total example
- #include<stdio.h>
- #include<stdlib.h> //link list library header
- #include<string.h> //String library header
- ///Structure create
- typedef struct Node
- {
- char name[15];
- char phn[12];
- char email[20];
- struct Node *next;
- } node;
- ///Global Variable
- int count=0;
- node *head = NULL;
- node *temp = NULL;
- /// Insert data at begin of list...
- void insertAtbigen()
- {
- printf("Enter number of total list :");
- int i,n;
- scanf("%d",&n);
- for(i=0; i<n; i++)
- {
- printf("\nEnter Node information: #%d\n",i+1);
- node *newnode;
- newnode=(node*)malloc(sizeof(node));
- printf("Enter Name:");scanf("%s", &newnode-> name);
- printf("Enter Phone Number:");scanf("%s", &newnode-> phn);
- printf("Enter Email Address:");scanf("%s", &newnode-> email);
- count++;
- newnode->next=NULL;
- if(head==NULL)
- {
- head=newnode;
- }
- else
- {
- newnode->next=head;
- head=newnode;
- }
- }
- }
- /// insert at end of list....
- void insertAtend()
- {
- printf("Enter number of total list:");
- int i,n;
- scanf("%d",&n);
- for(i=0; i<n; i++)
- {
- printf("\nEnter Node information: #%d\n",i+1);
- node *newnode;
- newnode=(node*)malloc(sizeof(node));
- printf("Enter Name:");scanf("%s", &newnode-> name);
- printf("Enter Phone Number:");scanf("%s", &newnode-> phn);
- printf("Enter Email Address:");scanf("%s", &newnode-> email);
- count++;
- newnode->next=NULL;
- if(head==NULL)
- {
- head=newnode;
- }
- else
- {
- temp=head;
- while(temp->next!=NULL)
- {
- temp=temp->next;
- }
- temp->next=newnode;
- }
- }
- }
- ///print all data ....
- void printList()
- {
- temp = head;
- printf("\n---------Show Node list Information:---------\n");
- int c=1;
- while(temp != NULL)
- {
- printf("\nDisplay Node information: #%d\n",c++);
- printf("Name: %s\n",temp-> name);
- printf("Phone: %s\n",temp-> phn);
- printf("Email: %s\n",temp-> email);
- temp= temp-> next;
- }
- }
- ///searching area......
- void searchNode()
- {
- printf("\n---------Search part:---------\n");
- temp=head;
- printf("Searching by any value for press-1\n");
- printf("Searching by position for press-2\n");
- ///Searching by any value....
- int s;
- scanf("%d",&s);
- if(s==1)
- {
- char src[20];
- printf("Enter search value name or email:");
- scanf("%s",src);
- while(temp!=NULL && ((strcmp(temp->name,src)!=0) && (strcmp(temp->email,src)!=0)))
- {
- temp=temp-> next;
- }
- if(temp==NULL)
- {
- printf("Not Found\n");
- }
- else { printf("\nSearch Friend information:\n");
- printf("Name: %s\n",temp-> name);
- printf("Phone: %s\n",temp-> phn);
- printf("Email: %s\n",temp-> email);
- }
- }
- ///Searching by position.......
- else if(s==2)
- {
- int position,po=1;
- printf("Enter Position:");
- scanf("%d",&position);
- while(temp!=NULL && position>count && position!=po)
- {
- temp=temp-> next;
- po++;
- }
- if(temp==NULL || position>count)
- {
- printf("Not Founded entered your position\n");
- }
- else { printf("\nFounded your Position #%d no information:\n",position);
- printf("Name: %s\n",temp-> name);
- printf("Phone: %s\n",temp-> phn);
- printf("Email: %s\n",temp-> email);
- }
- }
- }
- ///Delete or Update Area...
- void deleteeNode()
- {
- printf("\n---------Delete or Update part:---------\n");
- node *pre=NULL;
- temp=head;
- printf("Searching by any value for press-1\n");
- printf("Searching by position for press-2\n");
- ///Searching & deleted by any value....
- int s;
- scanf("%d",&s);
- if(s==1)
- {
- char src[20];
- printf("Enter search value name or email:");
- scanf("%s",src);
- while(temp!=NULL && ((strcmp(temp->name,src)!=0) && (strcmp(temp->email,src)!=0)&&(strcmp(temp->phn,src)!=0)))
- {
- pre=temp;
- temp=temp-> next;
- }
- if(temp==NULL)
- {
- printf("Not Found\n");
- }
- else { printf("\nSearch Friend information:\n");
- printf("Name: %s\n",temp-> name);
- printf("Phone: %s\n",temp-> phn);
- printf("Email: %s\n",temp-> email);
- printf("Enter 1 for delete or Enter 2 for Edit..\n");
- int d;
- scanf("%d",&d);
- if(2==d)
- {
- printf("Enter update Name:");scanf("%s", &temp-> name);
- printf("Enter update Phone Number:");scanf("%s", &temp-> phn);
- printf("Enter update Email Address:");scanf("%s", &temp-> email);
- printf("Update Successfully\n\n");
- }
- else if(d==1)
- {
- if(temp==head)
- {
- head=temp->next;
- printf("\nInformation of %s has deleted successfully \n",temp->name);
- free(temp);
- --count;
- }
- pre->next=temp->next;
- printf("\nInformation of %s has deleted successfully \n",temp->name);
- free(temp);
- --count;
- }
- }
- }
- ///Searching & deleted by position....
- else if(s==2)
- {
- int position,po=1;
- printf("Enter Position:");
- scanf("%d",&position);
- while(temp!=NULL && position>count && position==po)
- {
- pre=temp;
- temp=temp-> next;
- po++;
- }
- if(temp==NULL || position>count)
- {
- printf("Not Founded entered your position\n");
- }
- else { printf("\nFounded your Position #%d no information:\n",position);
- printf("Name: %s\n",temp-> name);
- printf("Phone: %s\n",temp-> phn);
- printf("Email: %s\n",temp-> email);
- printf("Enter 1 for delete or Enter 2 for Edit..\n");
- int d;
- scanf("%d",&d);
- if(2==d)
- {
- printf("Enter update Name:");scanf("%s", &temp-> name);
- printf("Enter update Phone Number:");scanf("%s", &temp-> phn);
- printf("Enter update Email Address:");scanf("%s", &temp-> email);
- printf("Update Successfully\n\n");
- }
- else if(d==1)
- {
- if(temp==head)
- {
- head=temp->next;
- printf("\nInformation of %s has deleted successfully \n",temp->name);
- free(temp);
- --count;
- }
- pre->next=temp->next;
- printf("\nInformation of %s has deleted successfully \n",temp->name);
- free(temp);
- --count;
- }
- }
- }
- }
- ///Main Body Section......
- int main()
- {
- for(;;)
- {
- int k;
- printf("\n1.Create list At Begin\n");
- printf("2.Create list At End\n");
- printf("3.Searching\n");
- printf("4.delete or Update\n");
- printf("5.Display list\n");
- printf("6.Count list\n");
- printf("7.Exit\n");
- scanf("%d",&k);
- if(k==1){insertAtbigen();}
- else if(k==2){insertAtend();}
- else if(k==3){searchNode();}
- else if(k==4){deleteeNode();}
- else if(k==5){printList();}
- else if(k==6){printf("Toatl List of Node ----- %d\n",count);}
- else { break;}
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement