

















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A part of the EE 232 Data Structures course materials, focusing on Lists, Stacks, and Queues. It includes programming details, common errors, and problem-solving strategies. Students will learn about abstract data types, list implementation, and common errors in handling linked lists.
Typology: Slides
1 / 25
This page cannot be seen from the preview
Don't miss anything!


















/* Return Position of X in L; NULL if not found */
/* If X is not found, then Next field of returned value is NULL / / Assumes a header */
The List ADT…
/* Assume use of a header node / / Cell pointed to by P->Next is wiped out / / Assume that the position is legal / void Delete( ElementType X, List L ) { Position P, TmpCell; P = FindPrevious( X, L ); if( !IsLast( P, L ) ) { / X is found; delete it / TmpCell = P->Next; / Bypass deleted cell */ P->Next = TmpCell->Next; free( TmpCell ); } }
/* Insert (after (This decision is arbitrary) legal position P) / / Header implementation assumed / void Insert( ElementType X, List L, Position P ) { Position TmpCell; / 1/ TmpCell = malloc( sizeof( struct Node ) ); / 2/ if( TmpCell == NULL ) / 3/ FatalError( "Out of space!!!" ); / 4/ TmpCell->Element = X; / 5/ TmpCell->Next = P->Next; / 6*/ P->Next = TmpCell; }
/* Correct DeleteList algorithm / void DeleteList( List L ) { Position P, Tmp; / 1/ P = L->Next; / Header assumed / / 2/ L->Next = NULL; / 3/ while( P != NULL ) { / 4/ Tmp = P->Next; / 5/ free( P ); / 6*/ P = Tmp; } }
/* Correct DeleteList algorithm / void DeleteList( List L ) { Position P, Tmp; / 1/ P = L->Next; / Header assumed / / 2/ L->Next = NULL; / 3/ while( P != NULL ) { / 4/ Tmp = P->Next; / 5/ free( P ); / 6*/ P = Tmp; } }
1 A double circularly linked list with no header
typedef struct { int CoeffArray[MaxDegree + 1]; unsigned int HighPower; } *Polynomial; void ZeroPolynomial( Polynomial Poly ) { int i; for( i = 0; i <= MaxDegree; i++ ) Poly->CoeffArray[ i ] = 0; Poly->HighPower = 0; }
Lists, Stacks, and Queues (^3) - 17
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 <= Poly1->HighPower; i++ ) for( j = 0; j <= Poly2->HighPower; j++ ) PolyProd->CoeffArray[ i + j ] += Poly1->CoeffArray[ i ] * Poly2->CoeffArray[ j ]; }
1990 1492 2 1000 14 1
2 NULL Each node has the coefficient, the exponent, and the pointer to next
Lists, Stacks, and Queues (^3) - 20