Skip to main content

Write a C Program that uses functions to perform the following operations on a double linked list Creation, Insertion, Deletion

 

#include<stdio.h>

 #include<stdlib.h>

 struct node

 {               

 struct node *prev;

 struct node *next;

 int data;

 };

 struct node *head;

 void insertion_beginning();

 void insertion_last();

 void deletion_beginning();

 void deletion_last();

 void display();

 void search();

 void main ()

 {

 int choice =0;

 while(choice != 9)

 {

 printf("\nMain Menu\n");

 printf("\nChoose one option:\n");

 

 printf("\n1.Insert in Beginning\n2.Insert at last\n3.Delete from Beginning\n4.Delete from last\n5.Search\n6.Show\n7.Exit\n");

 printf("\nEnter your choice?\n");

 scanf("\n%d",&choice);

 switch(choice)

  {

 case 1:

 insertion_beginning();

 break;

 case 2:

 insertion_last();

 break;

 case 3:

 deletion_beginning();

 break;

 case 4:

 deletion_last();

 break;

 case 5:

 search();

 break;

 case 6:

 display();

 break;

 case 7:

     printf("\nPiyush \n 315/CSE/2019");

 exit(0);

 break;

 default:

 printf("Please enter valid choice..");

 }

 }

 }

 

 void insertion_beginning()

 {

 struct node *ptr,*temp;

 int item;

 ptr = (struct node *)malloc(sizeof(struct node));

 if(ptr == NULL)

 {

 printf("\nOVERFLOW");

 }

 else

 {

 printf("\nEnter Item value");

 scanf("%d",&item);

 ptr->data=item;

 if(head==NULL)

 {

 head = ptr;

 ptr -> next = head;

 ptr -> prev = head;

 }

 else

 {

 temp = head;

 while(temp -> next != head)

 {

 temp = temp -> next;

 }

 temp -> next = ptr;

 ptr -> prev = temp;

 head -> prev = ptr;

 ptr -> next = head;

 head = ptr;

 }

 printf("\nNode inserted\n");

 }

 

 }

 

 void insertion_last()

 {

 struct node *ptr,*temp;

 int item;

 ptr = (struct node *) malloc(sizeof(struct node));

 if(ptr == NULL)

 {

 printf("\nOVERFLOW");

 }

 else

 {

 printf("\nEnter value");

 scanf("%d",&item);

 ptr->data=item;

 if(head == NULL)

 {

 head = ptr;

 ptr -> next = head;

 ptr -> prev = head;

 }

 else

 {

 temp = head;

 while(temp->next !=head)

 {

 temp = temp->next;

 }

 temp->next = ptr;

 ptr ->prev=temp;

 head -> prev = ptr;

 ptr -> next = head;

 }

 }

 printf("\nnode inserted\n");

 }

 

 void deletion_beginning()

 {

 struct node *temp;

 if(head == NULL)

 {

 printf("\n UNDERFLOW");

 }

 else if(head->next == head)

   {

 head = NULL;

 free(head);

 printf("\nnode deleted\n");

 }

 else

 {

 temp = head;

 while(temp -> next != head)

 {

 temp = temp -> next;

 }

 temp -> next = head -> next;

 head -> next -> prev = temp;

 free(head);

 head = temp -> next;

 }

 }

 void deletion_last()

 {

 struct node *ptr;

 if(head == NULL)

 {

 printf("\n UNDERFLOW");

 }

 else if(head->next == head)

 {

 head = NULL;

 free(head);

 printf("\nnode deleted\n");

 }

 else

 {

 ptr = head;

 if(ptr->next != head)

 {

 ptr = ptr -> next;

 }

 ptr -> prev -> next = head;

 head -> prev = ptr -> prev;

 free(ptr);

 printf("\nnode deleted\n");

 }

 }

 

 void display()

 {

 struct node *ptr;

 ptr=head;

 if(head == NULL)

 {

 printf("\nnothing to print");

 }

 else

 {

 printf("\n printing values ... \n");

 

 while(ptr -> next != head)

 {

 

 printf("%d\n", ptr -> data);

 ptr = ptr -> next;

 }

 printf("%d\n", ptr -> data);

 }

 }

 

 void search()

 {

 struct node *ptr;

 int item,i=0,flag=1;

 ptr = head;

 if(ptr == NULL)

 {

 printf("\nEmpty List\n");

 }

 else

 {

 printf("\nEnter item which you want to search?\n");

 scanf("%d",&item);

 if(head ->data == item)

 {

 printf("item found at location %d",i+1);

 flag=0;

 }

 else

 {

 while (ptr->next != head)

 {

 if(ptr->data == item)

 {

 printf("item found at location %d ",i+1);

 flag=0;

 break;

 }

 else

 {

 flag=1;

 }

 i++;

 ptr = ptr -> next;

 }

 }

 if(flag != 0)

 {

 printf("Item not found\n");

 }

 }

 }

Q10

#include<stdio.h>

#include<conio.h>

int min(int,int);

void floyds(int p[10][10],int n) {

                int i,j,k;

                for (k=1;k<=n;k++)

                  for (i=1;i<=n;i++)

                   for (j=1;j<=n;j++)

                    if(i==j)

                     p[i][j]=0; else

                     p[i][j]=min(p[i][j],p[i][k]+p[k][j]);

}

int min(int a,int b) {

                if(a<b)

                  return(a); else

                  return(b);

}

void main() {

                int p[10][10],w,n,e,u,v,i,j;

 

 

                printf("\n Enter the number of vertices:");

                scanf("%d",&n);

                printf("\n Enter the number of edges:\n");

                scanf("%d",&e);

                for (i=1;i<=n;i++) {

                                for (j=1;j<=n;j++)

                                   p[i][j]=999;

                }

                for (i=1;i<=e;i++) {

                                printf("\n Enter the end vertices of edge%d with its weight \n",i);

                                scanf("%d%d%d",&u,&v,&w);

                                p[u][v]=w;

                }

                printf("\n Matrix of input data:\n");

                for (i=1;i<=n;i++) {

                                for (j=1;j<=n;j++)

                                   printf("%d \t",p[i][j]);

                                printf("\n");

                }

                floyds(p,n);

                printf("\n Transitive closure:\n");

                for (i=1;i<=n;i++) {

                                for (j=1;j<=n;j++)

                                   printf("%d \t",p[i][j]);

                                printf("\n");

                }

                printf("\n The shortest paths are:\n");

                for (i=1;i<=n;i++)

                  for (j=1;j<=n;j++) {

                                if(i!=j)

                                    printf("\n <%d,%d>=%d",i,j,p[i][j]);

                }

             

                getch();

}


Comments

Popular posts from this blog

Windows 11 Pro Activation Key

 Windows 11 Pro key: W269N-WFGWX-YVC9B-4J6C9-T83GX Windows 11 Pro N key: MH37W-N47XK-V7XM9-C7227-GCQG9 Windows 11 Pro Workstations key: NRG8B-VKK3Q-CXVCJ-9G2XF-6Q84J Windows 11 Pro Workstations N key: 9FNHH-K3HBT-3W4TD-6383H-6XYWF Windows 11 Pro Education key: 6TP4R-GNPTD-KYYHQ-7B7DP-J447Y Windows 11 Home key: TX9XD-98N7V-6WMQ6-BX7FG-H8Q99 Windows 11 Home N key: 3KHY7-WNT83-DGQKR-F7HPR-844BM Windows 11 Home Home Single Language key: 7HNRX-D7KGG-3K4RQ-4WPJ4-YTDFH Windows 11 Home Country Specific: PVMJN-6DFY6-9CCP6-7BKTT-D3WVR Windows 11 Education key: NW6C2-QMPVW-D7KKK-3GKT6-VCFB2 Windows 11 Education N: 2WH4N-8QGBV-H22JP-CT43Q-MDWWJ Windows 11 Enterprise key: NPPR9-FWDCX-D2C8J-H872K-2YT43 Windows 11 Enterprise N key: DPH2V-TTNVB-4X9Q3-TJR4H-KHJW4 Windows 11 Enterprise G: YYVX9-NTFWV-6MDM3-9PT4T-4M68B Windows 11 Enterprise G N: 44RPN-FTY23-9VTTB-MP9BX-T84FV Windows 11 Enterprise LTSC 2019 key: M7XTQ-FN8P6-TTKYV-9D4CC-J462D Windows 11 Enterprise N LTSC 2019 key: 92NFX-8DJQP-P6BBQ-THF...

Colon Classification by(Vikram kumar)

Colon Classification is one of the most systematic schemes of Library Classifications used in many libraries in India and a few libraries abroad as well. This was devised by the late Dr. S.R. Ranganathan. He found the existing scheme of library classification unable to cope with the multidimensional dynamic growth of universe of subjects. Colon Classification proceeds in a different manner in spite of enumerating all possible subjects and their subdivisions, it analyses the subject in its various components and places them under five fundamental categories known as personality, matter, energy, space and time. To connect or to synthesize the various components of a subject, different connection symbols have been provided. Readymade class numbers are also available, but to build a class number, one has to analyze and pick up the possible isolates belonging to different fundamental categories which are then put together with the help appropriate connecting symbols. Colon Classifi...