Data Structure Programs 12,13 By:-Atul Enrollment No:-01516401520 Btech (I.T 1 Year)
Data Structure Programs 12,13 By:-Atul Enrollment No:-01516401520 Btech (I.T 1 Year)
Data Structure Programs 12,13 By:-Atul Enrollment No:-01516401520 Btech (I.T 1 Year)
Programs 12,13
By:-Atul
Enrollment no:-01516401520
Btech(I.T 1st year)
Program 12:-implement addition of two Polynomial expressions using singly
linked list.
Code
#include <stdio.h>
#include <conio.h>
#include <malloc.h>
struct node
{
int coeff;
int pow;
struct node *next;
};
//helper function
void show(struct node* Node)
{
while (Node->next != NULL) {
printf("%dx^%d", Node->coeff, Node->pow);
Node = Node->next;
if (Node->coeff >= 0) {
if (Node->next != NULL)
printf("+");
}
}
}
//add polynomials
void add_polynomial(struct node* poly1, struct node* poly2,
struct node* poly)
{
while (poly1->next && poly2->next) {
// If power of 1st polynomial is greater then 2nd,
// then store 1st as it is and move its pointer
if (poly1->pow > poly2->pow) {
poly->pow = poly1->pow;
poly->coeff = poly1->coeff;
poly1 = poly1->next;
}
void operation(){
struct node *poly1 = NULL, *poly2 = NULL, *poly = NULL;
poly = newnode;
// Function add two polynomial numbers
add_polynomial(poly1, poly2, poly);
int main()
{
operation();
return 0;
}
OUTPUTS
1)
2)
Program 13:-implement linear search and selection sort in a single linked list
Code
#include <stdio.h>
#include <stdlib.h>
struct LinkNode
{
int data;
struct LinkNode *next;
};
Outputs
1)
2)