Download presentation

Presentation is loading. Please wait.

Published byLogan Flynn Modified over 3 years ago

1
Application of linked list Geletaw S.

2
Linked list can be used in various environment. Some of the common examples are Creation of a polynomial Polynomial manipulation Sorting Creation of a tree Tree Traversals Multilist Organization

3
Creation of a Polynomial A node is used to create a list which consist of various components of the polynomial Example of a polynomial 4x^3 + 3x^2 + 2x + 1 Node1 Node2 Node3 Node4

4
The List contain node that has information about the polynomial degrees and coefficients Example 4x^3 Co-eff Power PointerField Co-eff Power PointerField 43.

5
Similarly for the polynomial 4x^3 + 3x^2 + 2x + 1, the linked list created is as follows Structure used to create a node: Struct node { int power; int coeff; struct node * next; // to point the next node in the list } 43322110

6
Procedure to create a polynomial Void create( ) { int s,c1; Struct node * p1, *n; root = p1 = NULL; cout<< enter the higher degree; cin>>deg; s = sizeof ( struct node *); for (I = deg; i>+0;I - - ) { cout<

7
Algorithm to create a polynomial The highest degree of the polynomial is obtained first Based on the degree the node is created The co-efficient and the corresponding power value is stored in the node The NEXT pointer is updated accordingly

8
Type declaration for array implementation of the polynomial ADT Typedef struct { int coeffarray[ Maxdegree + 1 ]; int Highpower ; } *Polynomial; Procedure to initialize a polynomial to zero Void zeroPolynomial( Polynomial Poly ) { int i; for( i=0; i<=Maxdegree; i++ ) Poly -> CoeffArray[ i ] = o Poly -> HighPower = o; }

9
Procedure to add two Polynomials Void AddPolynomial( const Polynomial Poly1, const Polynomial Poly2, Polynomail PolySum) { int i; zeroPolynomial( PolySum ); Polysum -> HighPower = Max( Poly1 -> HighPower,Poly2 -> Highpower); for( i= PolySum -> HighPower; i>=0; i++) PolySum ->CoeffArray[ i ] = Poly1 -> coeffArray [ i ] + Poly2 ->coeffArray[ i ]; }

10
PolySum Poly 1 4x^3 + 3x^2 + 2x + 1 Poly 2 5x^2 + 6x + 3 ( + ) ----------------------------------- PolySum 4x^3 + 8X^2 + 8x + 4

11
Procedure to Multiply 2 Polynomials Void MultPolynomial( const Polynomial Poly1, const Polynomial Poly2, Polynomial PolyProd) { int i,j; zeroPolynomial( PolyProd ); PolyProd -> HighPower = Poly1 -> highPower + Poly2 ->HighPower; if( PolyProd -> HighPower > MaxDegree) error( Exceeded array Size); else for( i=0; i highPower; i++) for( j=0; j HighPower; J++) PolyProd -> coeffArray [ i+j ] = Poly1 -> coeffArray [i] * Poly2 -> coeffArray [j]; }

12
PolyProd Poly 1 4x^3 + 3x^2 + 2x + 1 Poly 2 5x^2 + 6x + 3 ( * ) ----------------------------------- 20x^5 + 24x^4 + 12x^3 + 15x^4 + 18x^3 + 6x^2 + 10x^3 + 12x^2 + 6x + 5x^2 + 6x + 3 PolyProd 20x^5 + 39x^4 + 40x^3 + 23x^2 + 12x + 3

13
Radix Sort It is performed using buckets from 0 to 9 The digit position of a number is used to perform sorting The number of passes in a radix sort depends on the number of digits in the given number It is also called as Card Sort

14
Example 42, 24, 11, 36, 54, 10, 19, 27, 45. The number of digits n the numbers are 2, hence the number of passes are 2 42, 24, 11, 36, 54, 10, 19, 27, 45. The number of digits n the numbers are 2, hence the number of passes are 2 Pass 1 3254 1011422445362719 0123456789

15
The number has been placed in their corresponding pockets based on their unit digit. 10 is placed in pocket 0 27 is placed in pocket 7 Collect back all the nos from the pockets 10,11,42,32,24,54,45,36,27,19

16
Now place all the nos in the pockets based on tenth digit position. 10 is placed in pocket 1 27 is placed in pocket 2 11273645 1024324254 0123456789

Similar presentations

Presentation is loading. Please wait....

OK

Chapter 3: Linked List Tutor: Angie Hui

Chapter 3: Linked List Tutor: Angie Hui

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google

Oppt one people's public trust Ppt on non biodegradable waste images Ppt on electromagnetism theory Best ppt on social networking sites Ppt on sources of energy Ppt on electricity for class 10 Ppt on biopotential signals Ppt on zener diode polarity Ppt on south african culture and traditions Ppt on success and failure in business