• 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

Circular Link List using C Language

April 5, 2011 by ProjectsGeek Leave a Comment

Circular Link List using C Language

Represent single variable polynomial as a circular link list. Accept the terms in the polynomial in any order, i.e. not necessarily in the decreasing order of exponent. Sort while creating polynomial in the decreasing order of exponent and write a menu driven program to perform Circular Link List   display, addition, multiplication and evaluation.

 Concept of Circular Link List organization, singly linked list, doubly linked list, circular linked list.Linked list as ADT. Representation and manipulations of polynomials using linked lists,comparison of sequential linked organization with linked organization, concept Generalized Linked List.

Circular Link List using C Language Code

 #include  
 #include  
 #include  
 #include  
 typedef struct poly1  
 {  
 int pow;  
 float coeff;  
 struct poly1 *link;  
 }poly1;  
 poly1 *create();  
 void display(poly1 *);  
 poly1 *mul(poly1 *,poly1 *);  
 poly1 *add(poly1 *,poly1 *);  
 float evaluate(poly1 *,float);  
 poly1 *alloc();  
 int valid();  
 float validf();  
 poly1 *freeall(poly1 *);  
 void main()  
 {  
 poly1 *p1=NULL,*p2=NULL,*p3;  
 int ch,ch1;  
 float m;  
 float dummy;  
 &dummy;  
 clrscr();  
 do  
 {  
 clrscr();  
 printf("\n\t\tOPERATION ON POLYNOMIALS");  
 printf("\n\t\t1.CREATE\n\t\t2.DISPLAY\n\t\t3.ADDITION\n\t\t4.MULTPLICATION\n\t\t5.EVALUATION\n\t\t6.EXIT");  
 printf("\n\t\tENTER UR CHOICE:");  
 ch=valid();  
 switch(ch)  
 {  
 case 1: do  
 {  
 clrscr();  
 printf("\nCREATING POLYNOMIAL");  
 printf("\n\t\t1.FIRST POLY\n\t\t2.SECOMND POLY\n\t\t3.EXIT");  
 printf("\n\t\tENTER UR CHOICE:");  
 ch1=valid();  
 switch(ch1)  
 {  
 case 1: if(p1!=NULL)  
 freeall(p1);  
 printf("\n\t\tFIRST POLY");  
 p1=create();  
 break;  
 case 2: if(p2!=NULL)  
 freeall(p2);  
 printf("\n\t\tSECOND POLY");  
 p2=create();  
 break;  
 case 3:break;  
 default:printf("INVALID CHOICE");  
 }  
 }while(ch1!=3);  
 break;  
 case 2: do  
 {  
 clrscr();  
 printf("\nDISPLAYING POLYNOMIAL");  
 printf("\n\t\t1.FIRST POLY\n\t\t2.SECOMND POLY\n\t\t3.EXIT");  
 printf("\n\t\tENTER UR CHOICE:");  
 ch1=valid();  
 switch(ch1)  
 {  
 case 1: if(p1==NULL)  
 printf("\nEMPTY POLY");  
 else  
 {  
 printf("\n\t\tFIRST POLY");  
 display(p1);  
 }  
 getch();  
 break;  
 case 2: if(p2==NULL)  
 printf("\nEMPTY POLY");  
 else  
 {  
 printf("\n\t\tSECOND POLY");  
 display(p2);  
 }  
 getch();  
 break;  
 case 3:break;  
 default:printf("INVALID CHOICE");  
 getch();  
 }  
 }while(ch1!=3);  
 break;  
 case 3: if(p1==NULL&&p2==NULL)  
 printf("\nADDITION NOT POSSIBLE");  
 else  
 {  
 printf("\n\t\tADDITION");  
 p3=add(p1,p2);  
 if(p3==NULL)  
 printf("p3 is empty");  
 else  
 display(p3);  
 }  
 getch();  
 break;  
 case 4: if(p1==NULL&&p2==NULL)  
 printf("\nMULTIPLICATION NOT POSSIBLE");  
 else  
 {  
 printf("\n\t\tFIRST POLY*SECOND POLY");  
 p3=mul(p1,p2);  
 display(p3);  
 }  
 getch();  
 break;  
 case 5: do  
 {  
 clrscr();  
 printf("\n\t\tEVALUATION");  
 printf("\n\t\tENTER THE VALUE OF x:");  
 m=validf();  
 printf("\n\t\tEVALUATION ON");  
 printf("\n\t\t1.FIRST POLY\n\t\t2.SECOMND POLY\n\t\t3.EXIT");  
 printf("\n\t\tENTER UR CHOICE:");  
 ch1=valid();  
 switch(ch1)  
 {  
 case 1: if(p1==NULL)  
 printf("\nEVALUATION CANT BE DONE ON EMPTY POLY");  
 else  
 {  
 printf("\n\t\tFIRST POLY");  
 m=evaluate(p1,m);  
 printf("\n\tevaluation\t%f",m);  
 }  
 getch();  
 break;  
 case 2: if(p2==NULL)  
 printf("\nEVALUATION CANT BE DONE ON EMPTY POLY");  
 else  
 {  
 printf("\n\t\tSECOND POLY");  
 m=evaluate(p2,m);  
 printf("\n\tevaluation\t%f",m);  
 }  
 getch();  
 break;  
 case 3:break;  
 default:printf("INVALID CHOICE");  
 getch();  
 }  
 }while(ch1!=3);  
 break;  
 case 6: break;  
 default:printf("\n\t\tINVALID CHOICE");  
 getch();  
 }  
 }while(ch!=6);  
 }  
 /*poly1 *create()  
 {  
 poly1 *nw,*p,*t;  
 p=NULL;  
 do  
 {  
 nw=alloc(p);  
 if(nw!=NULL)  
 {  
 t=p;  
 if(p==NULL)  
 {  
 p=nw;  
 nw->link=p;  
 }  
 else  
 {  
 do  
 {  
 if(nw==t)  
 {  
 if(nw==p)  
 p=0;  
 else  
 p=nw;  
 break;  
 }  
 t=t->link;  
 }while(t!=p);  
 if(p!=0&&p!=nw)  
 {  
 if(nw->pow>p->pow)  
 {  
 while(t->link!=p)  
 t=t->link;  
 nw->link=p;  
 p=nw;  
 t->link=p;  
 }  
 else  
 {  
 while(t->link!=p && nw->powlink->pow)  
 t=t->link;  
 nw->link=t->link;  
 t->link=nw;  
 }  
 }  
 }  
 }  
 printf("\nDO U WANT ENTER MORE:y/n");  
 }while(getche()=='y');  
 return p;  
 }  
 poly1 *alloc(poly1* p)  
 {  
 poly1 *nw,*t,*n,*t1;  
 t=p;  
 nw=(poly1 *)malloc(sizeof(poly1));  
 while(1)  
 {  
 printf("\nENTER COEFF:");  
 nw->coeff=validf();  
 if(nw->coeff!=0)  
 break;  
 }  
 printf("\nENTER POWER:");  
 nw->pow=valid();  
 if(p!=NULL)  
 do  
 {  
 if(nw->pow==t->link->pow)  
 {  
 printf("\nthis power already exits");  
 printf("DO U WANT TO ADD IT IN PREVEIOUS:y/n");  
 if(getche()=='y')  
 {  
 t->link->coeff=t->link->coeff+nw->coeff;  
 if(t->link->coeff==0)  
 {  
 n=t->link;  
 t->link=t->link->link;  
 if(p->coeff==0)  
 {  
 p=p->link;  
 free(n);  
 free(nw);  
 return p;  
 }  
 free(n);  
 }  
 }  
 free(nw);  
 return(NULL);  
 }  
 t=t->link;  
 }while(t!=p);  
 return nw;  
 } */  
 void display( poly1 *p)  
 {  
 poly1 *t;  
 t=p;  
 do  
 {  
 if(t->coeff==1)  
 {  
 if(t->pow==0)  
 printf("%f",t->coeff);  
 }  
 else  
 printf("%f",t->coeff);  
 if(t->pow!=0)  
 printf("x");  
 if(t->pow>1)  
 printf("^%d",t->pow);  
 t=t->link;  
 if(t!=p)  
 if(t->coeff>0)  
 printf("+");  
 }while(t!=p);  
 getch();  
 }  
 float evaluate(poly1 *p,float x)  
 {  
 float result=0;  
 poly1 *t;  
 t=p;  
 do  
 {  
 result+=(t->coeff * pow(x,t->pow) );  
 t=t->link;  
 } while(t!=p);  
 return result;  
 }  
 poly1 *add(poly1 *p1,poly1 *p2)  
 {  
 poly1 *p3,*t,*s,*r,*last;  
 int flag=0,flag1=0;  
 t=p1;  
 s=p2;  
 p3=NULL;  
 last=p3;  
 if(p1==NULL)  
 return p2;  
 if(p2==NULL)  
 return p1;  
 do  
 {  
 r=(poly1 *)malloc(sizeof(poly1));  
 if(t->powpow)  
 {  
 r->pow=s->pow;  
 r->coeff=s->coeff;  
 s=s->link;  
 flag1=1;  
 }  
 else if(t->pow>s->pow)  
 {  
 r->pow=t->pow;  
 r->coeff=t->coeff;  
 t=t->link;  
 flag=1;  
 }  
 else  
 {  
 r->pow=t->pow;  
 r->coeff=t->coeff+s->coeff;  
 s=s->link;  
 t=t->link;  
 flag=1;  
 flag1=1;  
 }  
 if(r->coeff!=0)  
 {  
 if(p3==NULL)  
 {  
 p3=r;  
 }  
 else  
 {  
 last->link=r;  
 }  
 last=r;  
 }  
 else  
 free(r);  
 }while((t!=p1||flag==0)&&(s!=p2||flag1==0));  
 while(t!=p1||flag==0)  
 {  
 if(p3==NULL)  
 {  
 p3=r=(poly1 *)malloc(sizeof(poly1));  
 }  
 else  
 {  
 r->link=(poly1 *)malloc(sizeof(poly1));  
 r=r->link;  
 }  
 r->pow=t->pow;  
 r->coeff=t->coeff;  
 t=t->link;  
 flag=1;  
 last=r;  
 }  
 while(s!=p2||flag1==0)  
 {  
 if(p3==NULL)  
 {  
 p3=r=(poly1 *)malloc(sizeof(poly1));  
 }  
 else  
 {  
 r->link=(poly1 *)malloc(sizeof(poly1));  
 r=r->link;  
 }  
 r->pow=s->pow;  
 r->coeff=s->coeff;  
 s=s->link;  
 flag1=1;  
 last=r;  
 }  
 last->link=p3;  
 return p3;  
 }  
 poly1 *mul(poly1 *p1,poly1 * p2)  
 {  
 poly1 *p,*t,*r,*s,*n;  
 t=p1;  
 s=p2;  
 p=NULL;  
 r=NULL;  
 do  
 {  
 do  
 {  
 r=(poly1 *)malloc(sizeof(poly1));  
 r->coeff=t->coeff*s->coeff;  
 r->pow=t->pow+s->pow;  
 n=p;  
 if(p==NULL)  
 {  
 p=r;  
 r->link=p;  
 }  
 else  
 {  
 while(n->link!=p && r->powlink->pow)  
 n=n->link;  
 if(r->pow==n->link->pow)  
 {  
 n->link->coeff=r->coeff+n->link->coeff;  
 free(r);  
 if(n->link->coeff==0)  
 {  
 r=n->link;  
 n->link=p;  
 free(r);  
 }  
 }  
 else  
 {  
 r->link=n->link;  
 n->link=r;  
 }  
 }  
 t=t->link;  
 }while(t!=p1);  
 s=s->link;  
 }while(s!=p2);  
 return p;  
 }  
 poly1 *freeall(poly1 *p)  
 {  
 poly1 *t,*r;  
 r=p;  
 do  
 {  
 t=r;  
 r=r->link;  
 free(t);  
 }while(r!=p);  
 return p;  
 }  
 int valid()  
 {  
 int k,p;  
 char str[25];  
 k=-1;  
 do  
 {  
 k++;  
 str[k]=getche();  
 if(k>0)  
 if(str[k]=='\r')  
 {  
 str[k]='\0';  
 return(atoi(str));  
 }  
 if(str[k]<48 || str[k]>57)  
 {  
 printf("\ninvalid choice");  
 k--;  
 }  
 }while(str[k]!='\r');  
 return(0);  
 }  
 float validf()  
 {  
 int k,p,count=0;  
 char str[25];  
 k=-1;  
 do  
 {  
 k++;  
 str[k]=getche();  
 if(k>0)  
 if(str[k]=='\r')  
 {  
 str[k]='\0';  
 return(atof(str));  
 }  
 if(str[k]==46||str[k]==45)  
 count++;  
 if(((str[k]<48||str[k]>57)&& (str[k]!=46&&str[k]!=45)) || count>1)  
 {  
 printf("\ninvalid choice");  
 count=0;  
 k--; }  
 }while(str[k]!='\r');  
 return(0);  
 }  
 poly1 *create()  
 {  
 poly1 *nw,*p,*t,*r,*s;  
 p=NULL;  
 do  
 {  
 nw=alloc();  
 if(nw!=NULL)  
 {  
 t=p;  
 if(p==NULL)  
 {  
 p=nw;  
 nw->link=p;  
 }  
 else  
 {  
 if(nw->pow>p->pow)  
 {  
 while(t->link!=p)  
 t=t->link;  
 nw->link=p;  
 p=nw;  
 t->link=p;  
 }  
 else  
 {  
 while(t->link!=p && nw->pow<=t->link->pow)  
 t=t->link;  
 if(nw->pow==t->pow)  
 {  
 printf("\nthis power already exits");  
 printf("DO U WANT TO ADD IT IN PREVEIOUS:y/n");  
 if(getche()=='y')  
 {  
 t->coeff+=nw->coeff;  
 if(t->coeff==0)  
 {  
 if(p==p->link)  
 {  
 free(p);  
 p=NULL;  
 }  
 else  
 {  
 r=p;  
 while(r->link!=t)  
 r=r->link;  
 s=t;  
 if(p==t)  
 {  
 p=t->link;  
 }  
 r->link=t->link;  
 free(s);  
 }  
 }  
 }  
 free(nw);  
 }  
 else  
 {  
 nw->link=t->link;  
 t->link=nw;  
 }  
 }  
 }  
 }  
 printf("\nDO U WANT ENTER MORE:y/n");  
 }while(getche()=='y');  
 return p;  
 }  
 poly1 *alloc()  
 {  
 poly1 *nw;  
 nw=(poly1 *)malloc(sizeof(poly1));  
 while(1)  
 {  
 printf("\nENTER COEFF:");  
 nw->coeff=validf();  
 if(nw->coeff!=0)  
 break;  
 }  
 printf("\nENTER POWER:");  
 nw->pow=valid();  
 return nw;  
 }

Other Projects to Try:

  1. Expression Tree using C Language
  2. Breadth First and Depth First Search C Language
  3. Single Link List code using C Language
  4. Double Link List code using C Langauge
  5. Hash table code in C Language

Filed Under: C Assignments, Datastructure and Files 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