// Doubly circular linked list#include<stdio.h>#include<stdlib.h>
struct node{ int info; struct node *rpt; struct node *lpt;};struct node *first;
int main(){ struct node *cpt,*ptr,*tpt; int n,data,del; char ch; ptr=(struct node *)malloc(sizeof(struct node)); printf("Enter the First Node information:"); scanf("%d",&ptr->info); ptr->lpt=first; first=ptr; do { printf("\nPress 1 for creation:"); printf("\nPress 2 for display:"); printf("\nPress 3 for insertion at the beginning:"); printf("\nPress 4 for insertion at the end:"); printf("\nPress 5 for insertion at given info node:"); printf("\nPress 6 for deletion at the beginning:"); printf("\nPress 7 for deletion at the end:"); printf("\nPress 8 for deletion at the given info node:"); printf("\nPress 9 for exit:"); printf("\nEnter your choice:"); scanf("%d",&n); switch(n) { case 1: // creation of doubly linked list do { cpt=(struct node *)malloc(sizeof(struct node)); printf("\nEnter the information of next node:"); scanf("%d",&cpt->info); ptr->rpt=cpt; cpt->lpt=ptr; ptr=cpt; printf("\nPress y for more nodes:"); scanf("%s",&ch); } while(ch=='y'); ptr->rpt=first; first->lpt=ptr; case 2: // Display the doubly linked list ptr=first; do { printf("%d\t",ptr->info); ptr=ptr->rpt; } while(ptr!=first); break; case 3: // Insertion at the beginning ptr=first; cpt=(struct node *)malloc(sizeof(struct node)); printf("\nEnter the information of next node:"); scanf("%d",&cpt->info); tpt=ptr->lpt; cpt->rpt=ptr; ptr->lpt=cpt; cpt->lpt=tpt; tpt->rpt=cpt; first=cpt; break; case 4: // Insertion at the end cpt=(struct node *)malloc(sizeof(struct node)); printf("\nEnter the information of next node:"); scanf("%d",&cpt->info); ptr=first; tpt=ptr->lpt; cpt->rpt=ptr; ptr->lpt=cpt; cpt->lpt=tpt; tpt->rpt=cpt; break; case 5: // Insertion at given info node cpt=(struct node *)malloc(sizeof(struct node)); printf("\nEnter the information of next node:"); scanf("%d",&cpt->info); printf("\nProvide the info after which insertion has to be made:"); scanf("%d",&data); ptr=first; while(ptr->info!=data) { ptr=ptr->rpt; } tpt=ptr->rpt; ptr->rpt=cpt; cpt->lpt=ptr; cpt->rpt=tpt; tpt->lpt=cpt; break; case 6: // Deletion at the beginning ptr=first; tpt=ptr->lpt; cpt=ptr->rpt; cpt->lpt=tpt; tpt->rpt=cpt; first=cpt; free(ptr); break; case 7: // Deletion at the end ptr=first; tpt=ptr->lpt; cpt=tpt->lpt; cpt->rpt=ptr; ptr->lpt=cpt; free(tpt); break; case 8: // Deletion of a specific node ptr=first; printf("\nEnter the node to be deleted"); scanf("%d",&del); while(ptr->info!=del) { ptr=ptr->rpt; } cpt=ptr->lpt; tpt=ptr->rpt; cpt->rpt=tpt; tpt->lpt=cpt; break; } } while(n<9); return 0;}_______________________________________________________________________________ // C code for Doubly Linked List#include<stdio.h>#include<stdlib.h>
struct node{ int info; struct node *rpt; struct node *lpt;};struct node *first;
int main(){ struct node *cpt,*ptr,*tpt; int n,data,del; char ch; ptr=(struct node *)malloc(sizeof(struct node)); printf("Enter the First Node information:"); scanf("%d",&ptr->info); ptr->lpt=NULL; first=ptr; do { printf("\nPress 1 for creation:"); printf("\nPress 2 for display:"); printf("\nPress 3 for insertion at the beginning:"); printf("\nPress 4 for insertion at the end:"); printf("\nPress 5 for insertion at given info node:"); printf("\nPress 6 for deletion at the beginning:"); printf("\nPress 7 for deletion at the end:"); printf("\nPress 8 for deletion at the given info node:"); printf("\nPress 9 for exit:"); printf("\nEnter your choice:"); scanf("%d",&n); switch(n) { case 1: // creation of doubly linked list do { cpt=(struct node *)malloc(sizeof(struct node)); printf("\nEnter the information of next node:"); scanf("%d",&cpt->info); ptr->rpt=cpt; cpt->lpt=ptr; ptr=cpt; printf("\nPress y for more nodes:"); scanf("%s",&ch); } while(ch=='y'); ptr->rpt=NULL; case 2: // Display the doubly linked list ptr=first; while(ptr!=NULL) { printf("%d\t",ptr->info); ptr=ptr->rpt; } break; case 3: // Insertion at the beginning ptr=first; cpt=(struct node *)malloc(sizeof(struct node)); printf("\nEnter the information of next node:"); scanf("%d",&cpt->info); cpt->rpt=ptr; ptr->lpt=cpt; cpt->lpt=NULL; first=cpt; ptr=first; while(ptr!=NULL) { printf("%d\t",ptr->info); ptr=ptr->rpt; } break; case 4: // Insertion at the end cpt=(struct node *)malloc(sizeof(struct node)); printf("\nEnter the information of next node:"); scanf("%d",&cpt->info); ptr=first; while(ptr->rpt!=NULL) { ptr=ptr->rpt; } ptr->rpt=cpt; cpt->lpt=ptr; cpt->rpt=NULL; break; case 5: // Insertion at given info node cpt=(struct node *)malloc(sizeof(struct node)); printf("\nEnter the information of next node:"); scanf("%d",&cpt->info); printf("\nProvide the info after which insertion has to be made:"); scanf("%d",&data); ptr=first; while(ptr->info!=data) { ptr=ptr->rpt; } tpt=ptr->rpt; ptr->rpt=cpt; cpt->lpt=ptr; cpt->rpt=tpt; tpt->lpt=cpt; break; case 6: // Deletion at the beginning ptr=first; first=ptr->rpt; free(ptr); break; case 7: // Deletion at the end ptr=first; while(ptr->rpt!=NULL) { ptr=ptr->rpt; } cpt=ptr->lpt; cpt->rpt=NULL; free(ptr); break; case 8: // Deletion of a specific node ptr=first; printf("\nEnter the node to be deleted"); scanf("%d",&del); while(ptr->info!=del) { ptr=ptr->rpt; } cpt=ptr->lpt; tpt=ptr->rpt; cpt->rpt=tpt; tpt->lpt=cpt; break; } } while(n<9); return 0;}____________________________________________________________________________________
//Program for Singly Linked List #include <stdio.h>struct node { int info; struct node *link;};struct node *first;
int main(){ struct node *ptr,*cpt; int s; char n;
do{ printf("\nHi guys plase select the option to initiate the link list"); printf("\nPress 1 for creation"); printf("\nPress 2 for display"); printf("\nPress 3 for insertion at a given location"); printf("\nPress 4 to delete"); printf("\nPress 5 to terminate"); printf("\nEnter your choice:"); scanf("%d",&s); switch(s){ case 1: { //Create a new link list ptr=(struct node *)malloc(sizeof(struct node)); printf("ENTER THE VALUE"); scanf("%d",&ptr->info); first=ptr; do { cpt=(struct node *)malloc(sizeof(struct node)); printf("ENTER THE VALUE"); scanf("%d",&cpt->info); ptr->link=cpt; ptr=cpt; printf("\nEnter Y for more nodes"); scanf("%s",&n); } while(n=='y'); ptr->link=NULL; break; } case 2: // Display a linked list { ptr=(struct node *)malloc(sizeof(struct node)); ptr=first; while(ptr!=0) { printf("%d\t",ptr->info); ptr=ptr->link; } break; } case 3: //Insert at a given location { ptr=(struct node *)malloc(sizeof(struct node)); int data; struct node *tpt; tpt=(struct node *)malloc(sizeof(struct node)); printf("ENTER THE VALUE"); scanf("%d",&tpt->info); printf("Enter the location in which insertion has to be made!"); scanf("%d",&data); ptr=first; while(ptr->info!=data) { ptr=ptr->link; } tpt->link=ptr->link; ptr->link=tpt; ptr=(struct node *)malloc(sizeof(struct node)); ptr=first; while(ptr!=0) { printf("%d\t",ptr->info); ptr=ptr->link; } break; } case 4: { // Deletion of a specific location ptr=(struct node *)malloc(sizeof(struct node)); cpt=(struct node *)malloc(sizeof(struct node)); int loc; ptr=(struct node *)malloc(sizeof(struct node)); ptr=first; while(ptr!=0) { printf("%d\t",ptr->info); ptr=ptr->link; } printf("\nEnter the location where you have to delete:"); scanf("%d",&loc); ptr=first; while(ptr->info!=loc) { cpt=ptr; ptr=ptr->link; } cpt->link=ptr->link; ptr->link=NULL; } } }while(s<5);return 0;}______________________________________________________________________
// Program for Circular linked list#include<stdio.h>#include<stdlib.h>
struct node { int info; struct node *link;};struct node *first;
int main(){ int s; struct node *ptr,*cpt; struct node *tpt; int data; char ch; do { printf("\nPress 1 for Creation:"); printf("\nPress 2 for Display:"); printf("\nPress 3 for Insertion:"); printf("\nPress 4 for Terminate:"); printf("\nEnter your choice:"); scanf("%d",&s); switch(s) { case 1:// Creation of Doubly Linked List ptr=(struct node *)malloc(sizeof(struct node)); printf("\nEnter the first element:"); scanf("%d",&ptr->info); first=ptr; do { cpt=(struct node *)malloc(sizeof(struct node)); printf("\nEnter the next element:"); scanf("%d",&cpt->info); ptr->link=cpt; ptr=cpt; printf("\nPress y for new nodes:"); scanf("%s",&ch); } while(ch=='y'); ptr->link=first; break; case 2://Traversing the circular linked list ptr=first; do { printf("%d\t",ptr->info); ptr=ptr->link; } while(ptr!=first); break; case 3://Insertion at a given location tpt=(struct node *)malloc(sizeof(struct node)); printf("\nEnter the node information to be inserted"); scanf("%d",&tpt->info); printf("\nEnter Location"); scanf("%d",&data); ptr=first; while(ptr->info!=data) { cpt=ptr; ptr=ptr->link; } cpt->link=tpt; tpt->link=ptr; //Traversing the circular linked list ptr=first; do { printf("%d\t",ptr->info); ptr=ptr->link; } while(ptr!=first); } } while(s<4);
return 0;}
// Doubly circular linked list
#include<stdio.h>
#include<stdlib.h>
struct node
{
int info;
struct node *rpt;
struct node *lpt;
};
struct node *first;
int main()
{
struct node *cpt,*ptr,*tpt;
int n,data,del;
char ch;
ptr=(struct node *)malloc(sizeof(struct node));
printf("Enter the First Node information:");
scanf("%d",&ptr->info);
ptr->lpt=first;
first=ptr;
do
{
printf("\nPress 1 for creation:");
printf("\nPress 2 for display:");
printf("\nPress 3 for insertion at the beginning:");
printf("\nPress 4 for insertion at the end:");
printf("\nPress 5 for insertion at given info node:");
printf("\nPress 6 for deletion at the beginning:");
printf("\nPress 7 for deletion at the end:");
printf("\nPress 8 for deletion at the given info node:");
printf("\nPress 9 for exit:");
printf("\nEnter your choice:");
scanf("%d",&n);
switch(n)
{
case 1: // creation of doubly linked list
do
{
cpt=(struct node *)malloc(sizeof(struct node));
printf("\nEnter the information of next node:");
scanf("%d",&cpt->info);
ptr->rpt=cpt;
cpt->lpt=ptr;
ptr=cpt;
printf("\nPress y for more nodes:");
scanf("%s",&ch);
}
while(ch=='y');
ptr->rpt=first;
first->lpt=ptr;
case 2: // Display the doubly linked list
ptr=first;
do
{
printf("%d\t",ptr->info);
ptr=ptr->rpt;
}
while(ptr!=first);
break;
case 3: // Insertion at the beginning
ptr=first;
cpt=(struct node *)malloc(sizeof(struct node));
printf("\nEnter the information of next node:");
scanf("%d",&cpt->info);
tpt=ptr->lpt;
cpt->rpt=ptr;
ptr->lpt=cpt;
cpt->lpt=tpt;
tpt->rpt=cpt;
first=cpt;
break;
case 4: // Insertion at the end
cpt=(struct node *)malloc(sizeof(struct node));
printf("\nEnter the information of next node:");
scanf("%d",&cpt->info);
ptr=first;
tpt=ptr->lpt;
cpt->rpt=ptr;
ptr->lpt=cpt;
cpt->lpt=tpt;
tpt->rpt=cpt;
break;
case 5: // Insertion at given info node
cpt=(struct node *)malloc(sizeof(struct node));
printf("\nEnter the information of next node:");
scanf("%d",&cpt->info);
printf("\nProvide the info after which insertion has to be made:");
scanf("%d",&data);
ptr=first;
while(ptr->info!=data)
{
ptr=ptr->rpt;
}
tpt=ptr->rpt;
ptr->rpt=cpt;
cpt->lpt=ptr;
cpt->rpt=tpt;
tpt->lpt=cpt;
break;
case 6: // Deletion at the beginning
ptr=first;
tpt=ptr->lpt;
cpt=ptr->rpt;
cpt->lpt=tpt;
tpt->rpt=cpt;
first=cpt;
free(ptr);
break;
case 7: // Deletion at the end
ptr=first;
tpt=ptr->lpt;
cpt=tpt->lpt;
cpt->rpt=ptr;
ptr->lpt=cpt;
free(tpt);
break;
case 8: // Deletion of a specific node
ptr=first;
printf("\nEnter the node to be deleted");
scanf("%d",&del);
while(ptr->info!=del)
{
ptr=ptr->rpt;
}
cpt=ptr->lpt;
tpt=ptr->rpt;
cpt->rpt=tpt;
tpt->lpt=cpt;
break;
}
}
while(n<9);
return 0;
}
_______________________________________________________________________________
// C code for Doubly Linked List
#include<stdio.h>
#include<stdlib.h>
struct node
{
int info;
struct node *rpt;
struct node *lpt;
};
struct node *first;
int main()
{
struct node *cpt,*ptr,*tpt;
int n,data,del;
char ch;
ptr=(struct node *)malloc(sizeof(struct node));
printf("Enter the First Node information:");
scanf("%d",&ptr->info);
ptr->lpt=NULL;
first=ptr;
do
{
printf("\nPress 1 for creation:");
printf("\nPress 2 for display:");
printf("\nPress 3 for insertion at the beginning:");
printf("\nPress 4 for insertion at the end:");
printf("\nPress 5 for insertion at given info node:");
printf("\nPress 6 for deletion at the beginning:");
printf("\nPress 7 for deletion at the end:");
printf("\nPress 8 for deletion at the given info node:");
printf("\nPress 9 for exit:");
printf("\nEnter your choice:");
scanf("%d",&n);
switch(n)
{
case 1: // creation of doubly linked list
do
{
cpt=(struct node *)malloc(sizeof(struct node));
printf("\nEnter the information of next node:");
scanf("%d",&cpt->info);
ptr->rpt=cpt;
cpt->lpt=ptr;
ptr=cpt;
printf("\nPress y for more nodes:");
scanf("%s",&ch);
}
while(ch=='y');
ptr->rpt=NULL;
case 2: // Display the doubly linked list
ptr=first;
while(ptr!=NULL)
{
printf("%d\t",ptr->info);
ptr=ptr->rpt;
}
break;
case 3: // Insertion at the beginning
ptr=first;
cpt=(struct node *)malloc(sizeof(struct node));
printf("\nEnter the information of next node:");
scanf("%d",&cpt->info);
cpt->rpt=ptr;
ptr->lpt=cpt;
cpt->lpt=NULL;
first=cpt;
ptr=first;
while(ptr!=NULL)
{
printf("%d\t",ptr->info);
ptr=ptr->rpt;
}
break;
case 4: // Insertion at the end
cpt=(struct node *)malloc(sizeof(struct node));
printf("\nEnter the information of next node:");
scanf("%d",&cpt->info);
ptr=first;
while(ptr->rpt!=NULL)
{
ptr=ptr->rpt;
}
ptr->rpt=cpt;
cpt->lpt=ptr;
cpt->rpt=NULL;
break;
case 5: // Insertion at given info node
cpt=(struct node *)malloc(sizeof(struct node));
printf("\nEnter the information of next node:");
scanf("%d",&cpt->info);
printf("\nProvide the info after which insertion has to be made:");
scanf("%d",&data);
ptr=first;
while(ptr->info!=data)
{
ptr=ptr->rpt;
}
tpt=ptr->rpt;
ptr->rpt=cpt;
cpt->lpt=ptr;
cpt->rpt=tpt;
tpt->lpt=cpt;
break;
case 6: // Deletion at the beginning
ptr=first;
first=ptr->rpt;
free(ptr);
break;
case 7: // Deletion at the end
ptr=first;
while(ptr->rpt!=NULL)
{
ptr=ptr->rpt;
}
cpt=ptr->lpt;
cpt->rpt=NULL;
free(ptr);
break;
case 8: // Deletion of a specific node
ptr=first;
printf("\nEnter the node to be deleted");
scanf("%d",&del);
while(ptr->info!=del)
{
ptr=ptr->rpt;
}
cpt=ptr->lpt;
tpt=ptr->rpt;
cpt->rpt=tpt;
tpt->lpt=cpt;
break;
}
}
while(n<9);
return 0;
}
____________________________________________________________________________________
//Program for Singly Linked List
#include <stdio.h>
struct node
{
int info;
struct node *link;
};
struct node *first;
int main()
{
struct node *ptr,*cpt;
int s;
char n;
do
{
printf("\nHi guys plase select the option to initiate the link list");
printf("\nPress 1 for creation");
printf("\nPress 2 for display");
printf("\nPress 3 for insertion at a given location");
printf("\nPress 4 to delete");
printf("\nPress 5 to terminate");
printf("\nEnter your choice:");
scanf("%d",&s);
switch(s)
{
case 1:
{
//Create a new link list
ptr=(struct node *)malloc(sizeof(struct node));
printf("ENTER THE VALUE");
scanf("%d",&ptr->info);
first=ptr;
do
{
cpt=(struct node *)malloc(sizeof(struct node));
printf("ENTER THE VALUE");
scanf("%d",&cpt->info);
ptr->link=cpt;
ptr=cpt;
printf("\nEnter Y for more nodes");
scanf("%s",&n);
}
while(n=='y');
ptr->link=NULL;
break;
}
case 2: // Display a linked list
{
ptr=(struct node *)malloc(sizeof(struct node));
ptr=first;
while(ptr!=0)
{
printf("%d\t",ptr->info);
ptr=ptr->link;
}
break;
}
case 3: //Insert at a given location
{
ptr=(struct node *)malloc(sizeof(struct node));
int data;
struct node *tpt;
tpt=(struct node *)malloc(sizeof(struct node));
printf("ENTER THE VALUE");
scanf("%d",&tpt->info);
printf("Enter the location in which insertion has to be made!");
scanf("%d",&data);
ptr=first;
while(ptr->info!=data)
{
ptr=ptr->link;
}
tpt->link=ptr->link;
ptr->link=tpt;
ptr=(struct node *)malloc(sizeof(struct node));
ptr=first;
while(ptr!=0)
{
printf("%d\t",ptr->info);
ptr=ptr->link;
}
break;
}
case 4:
{
// Deletion of a specific location
ptr=(struct node *)malloc(sizeof(struct node));
cpt=(struct node *)malloc(sizeof(struct node));
int loc;
ptr=(struct node *)malloc(sizeof(struct node));
ptr=first;
while(ptr!=0)
{
printf("%d\t",ptr->info);
ptr=ptr->link;
}
printf("\nEnter the location where you have to delete:");
scanf("%d",&loc);
ptr=first;
while(ptr->info!=loc)
{
cpt=ptr;
ptr=ptr->link;
}
cpt->link=ptr->link;
ptr->link=NULL;
}
}
}
while(s<5);
return 0;
}
______________________________________________________________________
// Program for Circular linked list
#include<stdio.h>
#include<stdlib.h>
struct node
{
int info;
struct node *link;
};
struct node *first;
int main()
{
int s;
struct node *ptr,*cpt;
struct node *tpt;
int data;
char ch;
do
{
printf("\nPress 1 for Creation:");
printf("\nPress 2 for Display:");
printf("\nPress 3 for Insertion:");
printf("\nPress 4 for Terminate:");
printf("\nEnter your choice:");
scanf("%d",&s);
switch(s)
{
case 1:// Creation of Doubly Linked List
ptr=(struct node *)malloc(sizeof(struct node));
printf("\nEnter the first element:");
scanf("%d",&ptr->info);
first=ptr;
do
{
cpt=(struct node *)malloc(sizeof(struct node));
printf("\nEnter the next element:");
scanf("%d",&cpt->info);
ptr->link=cpt;
ptr=cpt;
printf("\nPress y for new nodes:");
scanf("%s",&ch);
}
while(ch=='y');
ptr->link=first;
break;
case 2://Traversing the circular linked list
ptr=first;
do
{
printf("%d\t",ptr->info);
ptr=ptr->link;
}
while(ptr!=first);
break;
case 3://Insertion at a given location
tpt=(struct node *)malloc(sizeof(struct node));
printf("\nEnter the node information to be inserted");
scanf("%d",&tpt->info);
printf("\nEnter Location");
scanf("%d",&data);
ptr=first;
while(ptr->info!=data)
{
cpt=ptr;
ptr=ptr->link;
}
cpt->link=tpt;
tpt->link=ptr;
//Traversing the circular linked list
ptr=first;
do
{
printf("%d\t",ptr->info);
ptr=ptr->link;
}
while(ptr!=first);
}
}
while(s<4);
return 0;
}
No comments:
Post a Comment