Question

In: Computer Science

Please find error and fill the blank and send as I can copy and paste like...

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;
}

Solutions

Expert Solution

All the blanks have been filled with the code. Please refer the code befor the blanks in the following C functions:

List CreateList( void )
{
           List L;

L = (List) malloc (sizeof (struct Node)); //________________________________; //BLANK FILLED
if( L == NULL )
Error( "Out of memory!" );
L->Next = NULL;
return L;
}

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 P; //_______; // BLANK FILLED
}

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*/ TmpCell -> Next = P -> Next; //____________________; // BLANK FILLED
/* 6*/ P->Next = TmpCell;
}

void
DeleteList( List L )
{
PtrToNode P, Tmp;

           P = L;
           while( P != NULL )
{
               Tmp = P->Next;
               free( P );
               P = Tmp; //____________; // BLANK FILLED
}
}

Position
Header( List L )
{
return L -> Next; // ________; // BLANK FILLED
}

Position
First( List L )
{
return L -> Next; //_________; // BLANK FILLED
}

Position
Advance( Position P )
{
return P -> Next;//___________; // BLANK FILLED
}

ElementType
Retrieve( Position P )
{
return P -> Element;//____________; // BLANK FILLED
}


Related Solutions

Can you solve and send me the original code which I can copy and paste plz....
Can you solve and send me the original code which I can copy and paste plz. Thank you. Kahn's Algorithm Implement Kahn's Algorithm for giving a topological ordering of a graph as discussed in class. The input graph will be in adjacency list format. 1. Count the in-degree (number of edges ending at) each vertex. 2. Create a queue of nodes with in-degree 0. 3. While the queue is not empty: a. Add the first element in the queue to...
**Please fill out the chart post at the bottom and please do not copy and paste...
**Please fill out the chart post at the bottom and please do not copy and paste a previous answer that has been used on CHegg. Lehighton Chalk Company manufactures sidewalk chalk, which it sells online by the box at $24 per unit. Lehighton uses an actual costing system, which means that the actual costs of direct material, direct labor, and manufacturing overhead are entered into work-in-process inventory. The actual application rate for manufacturing overhead is computed each year; actual manufacturing...
explain compounding and discounting ..please no copy and paste, I can google that myself.
explain compounding and discounting ..please no copy and paste, I can google that myself.
please i need unique answer , don't copy and paste ,, don't use handwriting.. can you...
please i need unique answer , don't copy and paste ,, don't use handwriting.. can you complete my answer , i need you answer b only Question: 3- Al Yamamah Steel Industries Co. uses the step method for allocating the costs of its service departments to operating departments. The company has two support departments (Human Resource and Information Technology) and two operating departments (Hot Rolled Hollow Steel and Cold Rolled Hollow Steel). Al Yamamah Steel Industries Co. decided to allocate...
( i need Unique answer, don't copy and paste, please) (dont' use handwriting, please). (i need...
( i need Unique answer, don't copy and paste, please) (dont' use handwriting, please). (i need references URL Link) General Question ** How to perform logistic regression in SPSS?
( i need Unique answer, don't copy and paste, please) (dont' use handwriting, please) (i need...
( i need Unique answer, don't copy and paste, please) (dont' use handwriting, please) (i need your reference URL Link) 1. Discuss charismatic traits and behaviors of a leader. How a person can manage relationship in workplace? i need more explain ( i need Unique answer, please) *** Please i need Unique answer, if you don't have unique answer don't answer ***
( i need Unique answer, don't copy and paste, please) (dont' use handwriting, please) (i need...
( i need Unique answer, don't copy and paste, please) (dont' use handwriting, please) (i need your reference URL Link) 1. Discuss charismatic traits and behaviors of a leader. How a person can manage relationship in workplace? i need more explain ( i need Unique answer, please) *** Please i need Unique answer, if you don't have unique answer don't answer ***
( i need Unique answer, don't copy and paste, please) (dont' use handwriting, please) (i need...
( i need Unique answer, don't copy and paste, please) (dont' use handwriting, please) (i need your reference URL Link) 1. Discuss charismatic traits and behaviors of a leader. How a person can manage relationship in workplace? i need more explain ( i need Unique answer, please) *** Please i need Unique answer, if you don't have unique answer don't answer ***
I.  Fill in Blank / Matching   Fill in the blanks with the appropriate terms below.  (2...
I.  Fill in Blank / Matching   Fill in the blanks with the appropriate terms below.  (2 pts. each = 20 pts.)   activity                        chemical                      resonance                    polychromatic             empirical electrons                      evaporation                 emission                      filtration                      filtrate gas                               hydrogen                     VESPR                       limiting                       liquid   mass                            mass percent               mole                            molecular                    oxide absorption                   oxygen                        physical                       precipitate                   precipitation    monochromatic           Lewis Dot                   supernatant                  periods                        groups     Many metals react readily with oxygen to form binary ____________ compounds.    ...
i need 500 words on this topic no copy paste please. Is the stock market "out...
i need 500 words on this topic no copy paste please. Is the stock market "out of control?" How can the poor benefit from this financial institution?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT