• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
projectsgeek

ProjectsGeek

Download Mini projects with Source Code, Java projects with Source Codes

  • Home
  • Java Projects
  • C++ Projects
  • VB Projects
  • PHP projects
  • .Net Projects
  • NodeJs Projects
  • Android Projects
    • Project Ideas
      • Final Year Project Ideas
      • JSP Projects
  • Assignment Codes
    • Fundamentals of Programming Language
    • Software Design Laboratory
    • Data Structure and Files Lab
    • Computer Graphics Lab
    • Object Oriented Programming Lab
    • Assembly Codes
  • School Projects
  • Forum

Double Link List code using C Langauge

April 3, 2011 by ProjectsGeek Leave a Comment

Implement Double Link List operations

 

Implement a Double Link list using C language to perform basic operations that can be performed on Double Link List . Some of the Basic Double Link list operations that can be implemented on Double Link List are Given Below ….

  • Create Double Link List
  • Display Double Link list
  • Delete Node
  • Insert Node

Double Link list assignment is implemented as Fundamentals of Data structure(FDS) as Second Year (SE-IT) Assignment under Pune University and Mumbai University .

Double Link list Code

#include  
 #include  
 typedef struct link  
 {  
 char c;  
 struct link *lptr,*rptr;  
 }dll;  
 dll* alloc(char ch)  
 {  
 dll* f;  
 f=(dll*)malloc(sizeof(dll));  
 f->rptr=NULL;  
 f->lptr=NULL;  
 f->c=ch;  
 return f;  
 }  
 dll* freeall(dll *f)  
 {  
 dll* temp;  
 while(f!=NULL)  
 {  
 temp=f;  
 f=f->rptr;  
 f->rptr->lptr=NULL;  
 free(temp);  
 }  
 return f;  
 }  
 dll* create()  
 {  
  dll *f,*nw;  
  char x;  
  f=NULL;  
  printf("\n Enter a string :");  
  flushall();  
  while((x=getchar())!='\n')  
   {  
 if(f==NULL)  
 {  
  nw=alloc(x);  
  f=nw;  
 }  
 else  
  {  
  nw->rptr=alloc(x);  
  nw->rptr->lptr=nw;  
  nw=nw->rptr;  
  nw->rptr=NULL;  
  }  
   }  
  return(f);  
 }  
 void reverse(dll *f)  
 {  
 dll *p;  
 p=f;  
 if(p==NULL)  
 {  
 printf("\n Empty list");  
 return;  
 }  
 printf("\n\nInfo\tleft ptr\taddress\t\tright ptr");  
 while(p->rptr!=NULL)  
 p=p->rptr;  
 printf("\n%c\t%d\t\t%d\t\t%d",p->c,p->lptr,p,p->rptr);  
 do  
 {  
 p=p->lptr;  
 printf("\n%c\t%d\t\t%d\t\t%d",p->c,p->lptr,p,p->rptr);  
 }while(p!=f);  
 }  
 //DISPLAYING THE LINKED LIST  
 void display(dll *f)  
 {  
 dll *p;  
 p=f;  
 if(p==NULL)  
 {  
 printf("\n Empty list");  
 return;  
 }  
 printf("\n\nInfo\tleft ptr\taddress\t\tright ptr");  
 while(p!=NULL)  
 {  
 printf("\n%c\t%d\t\t%d\t\t%d",p->c,p->lptr,p,p->rptr);  
 p=p->rptr;  
 }  
 }  
 dll* del(dll *f,char ch)  
 {  
 dll *temp;  
 temp=f;  
 while((temp!=NULL)&&(temp->c!=ch))  
 temp=temp->rptr;  
 if(temp==NULL)  
 {  
 printf("THE CHARACTER IS NOT FOUND");  
 return f;  
 }  
 if(temp!=f)  
 temp->lptr->rptr=temp->rptr;  
 else  
 f=temp->rptr;  
 if(temp->rptr!=NULL)  
 temp->rptr->lptr=temp->lptr;  
 free(temp);  
 printf("THE CHARACTER HAS BEEN DELETED");  
 return f;  
 }  
 void insert_a(dll*f,char ch)  
 {  
 dll *nw;  
 char a;  
 while((f!=NULL)&&(f->c!=ch))  
 f=f->rptr;  
 if(f==NULL)  
 printf("VALUE NOT FOUND");  
 else  
 {  
 printf("ENTER CHARACTER TO BE INSERTED");  
 flushall();  
 scanf("%c",&a);  
 nw=alloc(a);  
 nw->lptr=f;  
 nw->rptr=f->rptr;  
 f->rptr=nw;  
 if(nw->rptr!=NULL)  
 nw->rptr->lptr=nw;  
 }  
 }  
 dll* insert_b(dll *f,char ch)  
 {  
 dll *nw,*temp;  
 char a;  
 temp=f;  
 while((f!=NULL)&&(f->c!=ch))  
 f=f->rptr;  
 if(f==NULL)  
 {  
 printf("VALUE NOT FOUND");  
 return f;  
 }  
 printf("ENTER CHARACTER TO BE INSERTED");  
 flushall();  
 scanf("%c",&a);  
 nw=alloc(a);  
 nw->rptr=f;  
 nw->lptr=f->lptr;  
 f->lptr=nw;  
 if(nw->lptr!=NULL)  
 nw->lptr->rptr=nw;  
 else  
 temp=nw;  
 return temp;  
 }  
 void main()  
 {  
 dll *f;  
 int ch,i;  
 char c;  
 do  
 {  
 clrscr();  
 printf("\n\t\t\t\tMAIN MENU");  
 printf("\n\t\t\t1.Create\n\t\t\t2.Display\n\t\t\t3.Delete a node");  
 printf("\n\t\t\t4.Insert a node\n\t\t\t5.Display backwards \n\t\t\t6.Exit");  
 printf("\n\nEnter your choice : ");  
 flushall();  
 scanf("%d",&ch);  
 switch(ch)  
 {  
 case 1:  
 f=create();  
 printf("THE LIST HAS BEEN CREATED");  
 getch();  
 break;  
 case 2:  
 display(f);  
 getch();  
 break;  
 case 3:  
 printf("ENTER THE CHARACTER TO BE DELETED");  
 flushall();  
 scanf("%c",&c);  
 f=del(f,c);  
 getch();  
 break;  
 case 4: do  
 {  
 clrscr();  
 printf("\n\t\t\t\tINSERT\n");  
 printf("\n\t\t\t1.AFTER A CHARACTER\n");  
 printf("\n\t\t\t2.BEFORE A CHARACTER\n");  
 printf("\n\t\t\t3.EXIT\n");  
 printf("ENTER YOUR CHOICE : ");  
 flushall();  
 scanf("%d",&ch);  
 if(ch==1||ch==2)  
 {  
 printf("Enter that character : ");  
 flushall();  
 scanf("%c",&c);  
 }  
 switch(ch)  
 {  
 case 1: insert_a(f,c);  
 printf("\nThe value is inserted\n");  
 getch();  
 break;  
 case 2: f=insert_b(f,c);  
 printf("\nThe value is inserted\n");  
 getch();  
 break;  
 case 3:  
 break;  
 default:  
 printf("Invalid,enter again\n");  
 getch();  
 }  
 }while(ch!=3);  
 break;  
 case 5:  
 reverse(f);  
 getch();  
 break;  
 case 6:  
 break;  
 default:  
 printf("Invalid choice");  
 getch();  
 }  
 }while(ch!=6);  
 }

Download Source Code

 

Other Projects to Try:

  1. Single Link List code using C Language
  2. Circular Link List using C Language
  3. Sparse Matrix Operations Code using C Langauge
  4. String Operations with Pointers
  5. string operations such as Copy, Length, Reversing, Palindrome, Concatenation

Filed Under: Fundamentals of Datastructure Tagged With: Datastructure Assignments

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Tags

.Net Projects Download Android Project Ideas Android Projects Angular 2 Assembly Codes C # Projects C & C++ Projects C++ Projects Class Diagrams Computer Graphics Database Project Data Mining Projects DataScience Projects Datastructure Assignments Download Visual Basic Projects Electronics project Hadoop Projects Installation Guides Internet of Things Project IOS Projects Java Java Interview Questions Java Projects JavaScript JavaScript Projects java tutorial JSON JSP Projects Mechanical Projects Mongodb Networking Projects Node JS Projects OS Problems php Projects Placement Papers Project Ideas Python Projects seminar and presentation Struts

Search this Website


Footer

Download Java Project
Download Visual Basic Projects
Download .Net Projects
Download VB Projects
Download C++ Projects
Download NodeJs Projects
Download School Projects
Download School Projects
Ask Questions - Forum
Latest Projects Ideas
Assembly Codes
Datastructure Assignments
Computer Graphics Lab
Operating system Lab
australia-and-India-flag
  • Home
  • About me
  • Contact Form
  • Submit Your Work
  • Site Map
  • Privacy Policy