Application of Linked List (Addition of Two Polynomials)

preview_player
Показать описание
Data Structures: Application of Linked List (Addition of Two Polynomials)
Topics discussed:
1) C program to add the two polynomial using singly-linked lists.

Music:
Axol x Alex Skrindo - You [NCS Release]

#DataStructuresByNeso #DataStructures #LinkedList #LinkedListApplication
Рекомендации по теме
Комментарии
Автор

the perfect teacher... one with perfect pronunciation, perfect ppt, perfect voice, perfect everything, perfect what not??? huh? everything is awesome!!!!

sumitraj
Автор

Source code:

#include<stdio.h>
#include<stdlib.h>
struct node{
float co;
int expo;
struct node* link;
};
struct node* insert(struct node* head, float co, int expo)
{
struct node* temp=malloc(sizeof(struct node));
temp->co=co;
temp->expo=expo;
temp->link=NULL;
if(head==NULL || head->expo<expo)
{
temp->link=head;
head=temp;
}
else
{
struct node* temp1=head;
while(temp1->link!=NULL && temp1->link->expo>=expo)
{
temp1=temp1->link;
}
temp->link=temp1->link;
temp1->link=temp;
}
return head;
}
struct node* add(struct node* head, struct node* head1)
{
struct node* temp=head;
struct node* temp1=head1;
struct node* head2=NULL;

while(temp!=NULL && temp1!=NULL)
{
if(temp->expo==temp1->expo)
{
head2=insert(head2, temp->co+temp1->co, temp->expo);
temp=temp->link;
temp1=temp1->link;
}
else if(temp->expo>temp1->expo)
{
head2=insert(head2, temp->co, temp->expo);
temp=temp->link;
}
else if(temp1->expo>temp->expo)
{
head2=insert(head2, temp1->co, temp1->expo);
temp1=temp1->link;
}
}
while(temp!=NULL)
{
head2=insert(head2, temp->co, temp->expo);
temp=temp->link;
}
while(temp1!=NULL)
{
head2=insert(head2, temp1->co, temp1->expo);
temp1=temp1->link;
}
return head2;
}


struct node* create(struct node* head)
{
int n, expo;
float co;

printf("Enter the number of terms: ");
scanf("%d", &n);
for(int i=0;i<n;i++)
{
printf("\nEnter the coefficient of term %d: ", i+1);
scanf("%f", &co);
printf("\nEnter the exponent of term %d: ", i+1);
scanf("%d", &expo);
head=insert(head, co, expo);
}
printf("\n\n");
return head;
}
int main()
{
struct node* head=NULL;
struct node* head1=NULL;
struct node* head2=NULL;
head=create(head);
head1=create(head1);
head2=add(head, head1);
struct node* ptr=head2;
while(ptr!=NULL)
{
printf("(%.1fx^%d)", ptr->co, ptr->expo);
ptr=ptr->link;
if(ptr!=NULL)
{
printf("+");
}
else
printf("\n");


}
}

manojs
Автор

sir, I am a first-year engineering student and have been watching these videos for 3 months and I really understanding the concepts in-depth thank you for such wonderful videos. Sir, I only request you to increase the frequency of videos so we can learn all the concepts cause there is no teacher better than you.

dipeshjaswani
Автор

Today stacks has been started in my class, i hope you will upload videos before the mid sem.
Love❤️❤️❤️

rsingh
Автор

Sir this is huge request plzz complete this course

DeepakKumar-nkcv
Автор

Neso academy is the best channel to learn dsa in youtube

dheepanbalajil
Автор

Took me forever to learn from my textbook. But your explanation was something unimaginably easy and clear.
Thank you Sir!

atmos_
Автор

you are the best lecturer i have seen
thank u so much

AllInONE-ucgj
Автор

Sir make sure to continue the videos please continue sir🙏🙏🙏🙏🙏🙏

ramakrishnareddy
Автор

Jai ho maharaj 🙏🙏🙏.
Just continue the same..upload as many videos of DS and complete this course..
Thanks a ton. Cz of you i learned c language and DS 🙏

anveshatagore
Автор

Sir please Complete the Discrete Mathematics playlist as early as you can (Humble request). It is very much usefull to us in terms of concepts and understanding too... So I have also referred this playlist to many of my frnds. Only bcz it's incomplete, they are feeling somewhat inconvenience. (Going to another channel). So please complete it soon sir🙏

manjunadhkonapalli
Автор

Thanks sir from Kanpur 💕💯👌 good explanation of this session in YouTube

mohdtarik
Автор

Thanks for this video... 😇😇
Explanation was greart

hinayadav
Автор

Thanks for the video, I'm looking for recursive way to do this ?

benamarcoding
Автор

what is the use of the two while loops used in polyadd function after the first while loop

ketanpandey
Автор

Sir I want any of your instructors to teach design and analysis of algorithms this chapter was very important in the aspects of gate as well as in our curriculum currently we have this it is very helpful for us if u teach that subject

syedabuthahira
Автор

Why we use insert in addition of two polynomials

SaiKumar-cssf
Автор

sir its humble request to make videos on tree and graphs pls pls sir

nikgshort
Автор

How to insert the direct equation as a user input
Like i type x^2+5x+2 and the program should be understood the variables and operations (characters) ?

RutvikKumbhar
Автор

please upload videos on trees. I am searching everywhere but none of the video quality match yours and i understand your explanation well

sanchisingh