Please find error and fill the blank and send as I can copy and
paste like file or just codes if you can ?
1)
#include <stdio.h>
#include <stdlib.h>
#define Error( Str ) FatalError( Str )
#define FatalError( Str ) fprintf( stderr, "%s ", Str ), exit(
1 )
2) #include "list.h"
#include <stdlib.h>
#include "fatal.h"
/* Place in the interface file */
int Equal(ElementType x, ElementType y)
{
return x==y;
}
void Print(ElementType x)
{
printf("%2d", x);
}
List
CreateList( void )
{
List L;
L = ________________________________;
if( L == NULL )
Error( "Out of memory!" );
L->Next = NULL;
return L;
}
void
MakeEmpty( 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;
}
}
/* START: fig3_8.txt */
/* Return true if L is empty */
int
IsEmpty( List L )
{
return L->Next == NULL;
}
/* END */
/* START: fig3_9.txt */
/* Return true if P is the last position in list L */
/* Parameter L is unused in this implementation */
int IsLast( Position P, List L )
{
return P->Next == NULL;
}
/* END */
/* START: fig3_10.txt */
/* Return Position of X in L; NULL if not found */
Position
Find( ElementType X, List L )
{
Position P;
/* 1*/ P = L->Next;
/* 2*/ while( P != NULL && !Equal(P->Element,
X))
/* 3*/ P = P->Next;
/* 4*/ return _______;
}
/* END */
/* START: fig3_11.txt */
/* Delete (after legal position P) */
/* Assume use of a header node */
void
Delete(List L, Position P )
{
Position TmpCell;
TmpCell = P->Next;
P->Next = TmpCell->Next; /* Bypass deleted cell */
free( TmpCell );
}
/* END */
/* START: fig3_12.txt */
/* If X is not found, then Next field of returned value is
NULL */
/* Assumes a header */
Position
FindPrevious( ElementType X, List L )
{
Position P;
/* 1*/ P = L;
/* 2*/ while( P->Next != NULL &&
!Equal(P->Next->Element, X) )
/* 3*/ P = P->Next;
/* 4*/ return P;
}
/* END */
/* START: fig3_13.txt */
/* Insert (after legal position P) */
/* Header implementation assumed */
/* Parameter L is unused in this implementation */
void
Insert( ElementType X, List L, Position P )
{
Position TmpCell;
/* 1*/ TmpCell = (Position)malloc( sizeof( struct Node )
);
/* 2*/ if( TmpCell == NULL )
/* 3*/ Error( "Out of space!!!" );
/* 4*/ TmpCell->Element = X;
/* 5*/ ____________________;
/* 6*/ P->Next = TmpCell;
}
/* END */
/* START: fig3_15.txt */
/* Correct DeleteList algorithm */
void
DeleteList( List L )
{
PtrToNode P, Tmp;
P = L;
while( P != NULL )
{
Tmp = P->Next;
free( P );
____________;
}
}
/* END */
Position
Header( List L )
{
return ________;
}
Position
First( List L )
{
return _________;
}
Position
Advance( Position P )
{
return ___________;
}
ElementType
Retrieve( Position P )
{
return ____________;
}
void Modify( ElementType X, Position P )
{
P->Element = X;
}
void PrintList(List L)
{
Position pL;
ElementType e;
pL = First(L);
while (pL) {
e = Retrieve(pL);
Print(e);
pL = Advance(pL);
}
printf(" ");
}
3)
#ifndef _List_H
#define _List_H
typedef int ElementType;
struct Node {
ElementType Element;
struct Node *Next;
};
typedef struct Node
*PtrToNode, *List, *Position;
void MakeEmpty( List L );
List CreateList( void );
int IsEmpty( List L );
int IsLast( Position P, List L );
Position Find( ElementType X, List L );
void Delete( List L, Position P );
Position FindPrevious( ElementType X, List L );
void Insert( ElementType X, List L, Position P );
void DeleteList( List L );
Position Header( List L );
Position First( List L );
Position Advance( Position P );
ElementType Retrieve( Position P );
void Modify( ElementType X, Position P );
void PrintList(List L);
#endif /* _List_H */
/* END */
4)
#include "stdio.h"
#include "list.h"
#include "fatal.h"
List Union(List A, List B) {
List C;
Position pA, pB, pC;
ElementType e;
C = CreateList();
pC = Header(C);
pA = First(A);
while (pA) {
e = Retrieve(pA);
Insert(e, C, pC);
pA = Advance(pA);
}
pB = First(B);
while (pB) {
e = Retrieve(pB);
if (!Find(e, A))
Insert(e, C, pC);
pB = Advance(pB);
}
return C;
}
int main() {
List A, B, C;
int j;
A = CreateList(); B = CreateList();
printf("Please input set A(finished with -1): ");
scanf("%d", &j);
while (j != -1){
Insert(j, A, Header(A));
scanf("%d", &j);
}
printf("A:"); PrintList(A);
printf("Please input set B(finished with -1): ");
scanf("%d", &j);
while (j != -1){
Insert(j, B, Header(B));
scanf("%d", &j);
}
printf("B:"); PrintList(B);
C = Union(A, B);
printf("C:"); PrintList(C);
DeleteList(A); DeleteList(B); DeleteList(C);
return 1;
}