SlideShare ist ein Scribd-Unternehmen logo
1 von 14
There are a number of errors in the following program.
All errors are located in main() and structure definitions.
Function declarations and definitions are correct!
Locate all errors, fix them (as shown below), run the program and save its output
as a comment at the end of the source file.
Example:
int num = 10;
int *ptr;
num = &ptr; // <== Error: Comment the line and write the correct line below
// Write a short justification where appropriate
// num = &ptr; // Error #1
ptr = &num;
Name:
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#define DUMMY_TRAILER '177'
// octal ASCII code of the
// last character in the ASCII table
#define NUM_CITIES 10
typedef struct
{
char name[12];
int temperature[5];
} CITY;
// Stack and Queue Node
typedef struct node NODE;
struct node
{
CITY city;
node *next;
};
// Doubly Linked List Node
typedef struct d_node D_NODE;
struct d_node
{
CITY city;
NODE *forw;
NODE *back;
};
// Stack Functions
NODE *push(NODE *stack, const CITY *pStu);
NODE *pop(NODE **stack);
// Queue Functions
void enqueue(NODE **queue, NODE **rear, const CITY *pStu);
NODE *dequeue(NODE **queue, NODE **rear);
// Doubly Linked List Functions
D_NODE *init_list(void);
int insert(D_NODE *list, const CITY *pStu);
void traverse_forw(D_NODE *list);
void traverse_back(D_NODE *list);
// Other Functions
void printCity(const CITY *pCity);
int main (void)
{
CITY cList[NUM_CITIES] =
{
{"Cupertino", {88, 89, 87, 85, 89}},
{"Flagstaff", {81, 80, 88, 89, 89}},
{"Los Angeles", {87, 88, 89, 89, 90}},
{"Philadelphia", {96, 99, 99, 90, 95}},
{"Phoenix", {106, 109, 109, 100, 105}},
{"Portland", {89, 90, 85, 89, 90}},
{"Reno", {108, 105, 109, 100, 108}},
{"Salem", {85, 90, 85, 89, 90}},
{"Tucson", {107, 100, 109, 100, 108}},
{"Yreka", {101, 109, 100, 108, 109}}
};
NODE *stack = NULL;
NODE *top = NULL;
NODE *queue = NULL, *rear = NULL;
NODE *front;
D_NODE *list;
list = init_list();
// build stack and queue with data from an array of CITY structures
srand((unsigned int)time(NULL));
int count = rand() % 10;
for ( int n = 0; n < count; n++)
{
int i = rand() % NUM_CITIES;
int duplicate = insert(list, &cList[i]);
if(duplicate)
{
// already in the list!
push(stack, &cList[i]);
enqueue(&queue, &rear, cList[i]);
}
}
// display list
printf("nLIST contents (forwards):n");
traverse_forw(list);
printf("nLIST contents (backwards):n");
traverse_back(list);
// display stack
if (top)
{
printf("nSTACK contents from top to bottom:n");
while ((top = pop(stack)))
{
printCity(top->city);
}
}
else
printf ("Empty Stack!n");
// display queue
if (front)
{
printf("nQUEUE contents from front to rear:n");
while ((front = dequeue( queue, rear)))
{
printCity(front->city);
}
}
else
printf ("Empty Queue!n");
return 0;
}
/***************************************************
Displays the fileds of a CIS_CLASS structure
Pre pCls - a pointer to a CIS_CLASS structure
Post
*/
void printCity(const CITY *pCity)
{
printf("%-20s %3dn", pCity->name, pCity->temperature[0]);
}
// Stack Functions
/***************************************************
Stack Insert: insert in the beginning
*/
NODE *push(NODE *stack, const CITY *pCity)
{
NODE *pnew;
pnew = (NODE *) malloc(sizeof (NODE));
if (!pnew)
{
printf("... error in push!n");
exit(1);
}
pnew->city = *pCity;
pnew->next = stack;
stack = pnew;
return stack;
}
/***************************************************
Stack Delete: delete the first node
*/
NODE *pop(NODE **stack)
{
NODE *first;
if (*stack == NULL) return NULL;
first = *stack;
*stack = (*stack)->next;
first->next = NULL;
return first;
}
// Queue Functions
/***************************************************
Queue Insert: insert at the end
*/
void enqueue(NODE **queue, NODE **rear, const CITY *pCity)
{
NODE *pnew;
pnew = (NODE *) malloc(sizeof (NODE));
if (!pnew)
{
printf("... error in enqueue!n");
exit(1);
}
pnew->city = *pCity;
pnew->next = NULL;
if (*queue == NULL) *queue = pnew;
else (*rear)->next = pnew;
*rear = pnew;
return;
}
/***************************************************
Queue Delete: remove the first node
*/
NODE *dequeue(NODE **queue, NODE **rear)
{
NODE *first;
if (*queue == NULL) return NULL;
first = *queue;
*queue = (*queue)->next;
if (*queue == NULL) *rear = NULL;
first->next = NULL;
return first;
}
// Doubly Linked List Functions
/***************************************************
Initialization of a circularly doubly-linked
list with one sentinel node
*/
D_NODE *init_list(void)
{
D_NODE *list;
// allocate the sentinel node
list = (D_NODE *) malloc(sizeof (D_NODE));
if (!list)
{
printf("Error in init_list!n");
exit(1);
}
list->city.name[0] = DUMMY_TRAILER;
list->city.name[1] = '0';
list->forw = list;
list->back = list;
return list;
}
/***************************************************
Insert a node in a sorted circularly
doubly-linked list with one sentinel node
return 1 - if duplicate
return 0 - otherwise
*/
int insert(D_NODE *list, const CITY *data)
{
D_NODE *curr = list->forw;
D_NODE *prev = list;
D_NODE *pnew;
int duplicate = 1;
// search
while (strcmp(data->name, curr->city.name) > 0)
{
prev = curr;
curr = curr->forw;
}
if (strcmp(data->name, curr->city.name) )
{
duplicate = 0; // not a duplicate
pnew = (D_NODE *) malloc(sizeof (D_NODE));
if (!pnew)
{
printf("Fatal memory allocation error in insert!n");
exit(3);
}
pnew->city = *data;
pnew->forw = curr;
pnew->back = prev;
prev->forw = pnew;
curr->back = pnew;
}
return duplicate;
}
/***************************************************
Traverses forward a circularly doubly-linked
list with one sentinel node to print out the
contents of each node
*/
void traverse_forw(D_NODE *list)
{
list = list->forw; // skip the dummy node
while (list->city.name[0] != DUMMY_TRAILER)
{
printCity(&list->city);
list = list->forw;
}
}
/***************************************************
Traverses backward a circularly doubly-linked
list with one sentinel node to print out the
contents of each node
*/
void traverse_back(D_NODE *list)
{
list = list->back; // skip the dummy node
while (list->city.name[0] != DUMMY_TRAILER)
{
printCity(&list->city);
list = list->back;
}
}
/* ================= Sample Output #1 ================= */
/*
LIST contents (forwards):
Cupertino 88
Los Angeles 87
Philadelphia 96
Phoenix 106
Reno 108
Tucson 107
LIST contents (backwards):
Tucson 107
Reno 108
Phoenix 106
Philadelphia 96
Los Angeles 87
Cupertino 88
STACK contents from top to bottom:
Tucson 107
Philadelphia 96
QUEUE contents from front to rear:
Philadelphia 96
Tucson 107
*/
/* ================= Sample Output #2 ================= */
/*
LIST contents (forwards):
Flagstaff 81
Philadelphia 96
Yreka 101
LIST contents (backwards):
Yreka 101
Philadelphia 96
Flagstaff 81
Empty Stack!
Empty Queue!
*/

Weitere Àhnliche Inhalte

Ähnlich wie There are a number of errors in the following program- All errors are.docx

#include iostream #include fstream #include iomanip #.pdf
 #include iostream #include fstream #include iomanip #.pdf #include iostream #include fstream #include iomanip #.pdf
#include iostream #include fstream #include iomanip #.pdfKARTIKINDIA
 
maincpp Build and procees a sorted linked list of Patie.pdf
maincpp   Build and procees a sorted linked list of Patie.pdfmaincpp   Build and procees a sorted linked list of Patie.pdf
maincpp Build and procees a sorted linked list of Patie.pdfadityastores21
 
How do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdfHow do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdffeelinggift
 
Im having trouble figuring out how to code these sections for an a.pdf
Im having trouble figuring out how to code these sections for an a.pdfIm having trouble figuring out how to code these sections for an a.pdf
Im having trouble figuring out how to code these sections for an a.pdfrishteygallery
 
in this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdfin this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdfmichardsonkhaicarr37
 
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdf
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdfTHE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdf
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdffathimahardwareelect
 
pleaase I want manual solution forData Structures and Algorithm An.pdf
pleaase I want manual solution forData Structures and Algorithm An.pdfpleaase I want manual solution forData Structures and Algorithm An.pdf
pleaase I want manual solution forData Structures and Algorithm An.pdfwasemanivytreenrco51
 
Getting the following errorsError 1 error C2436 {ctor} mem.pdf
Getting the following errorsError 1 error C2436 {ctor}  mem.pdfGetting the following errorsError 1 error C2436 {ctor}  mem.pdf
Getting the following errorsError 1 error C2436 {ctor} mem.pdfherminaherman
 
#include iostream#include d_node.h #include d_nodel.h.docx
#include iostream#include d_node.h #include d_nodel.h.docx#include iostream#include d_node.h #include d_nodel.h.docx
#include iostream#include d_node.h #include d_nodel.h.docxajoy21
 
Circular linked list
Circular linked listCircular linked list
Circular linked listSayantan Sur
 
hi i have to write a java program involving link lists. i have a pro.pdf
hi i have to write a java program involving link lists. i have a pro.pdfhi i have to write a java program involving link lists. i have a pro.pdf
hi i have to write a java program involving link lists. i have a pro.pdfarchgeetsenterprises
 
I have the following code and I need to know why I am receiving the .pdf
I have the following code and I need to know why I am receiving the .pdfI have the following code and I need to know why I am receiving the .pdf
I have the following code and I need to know why I am receiving the .pdfezzi552
 
Write a program that accepts an arithmetic expression of unsigned in.pdf
Write a program that accepts an arithmetic expression of unsigned in.pdfWrite a program that accepts an arithmetic expression of unsigned in.pdf
Write a program that accepts an arithmetic expression of unsigned in.pdfJUSTSTYLISH3B2MOHALI
 
IN C LANGUAGE- I've been trying to finish this program for the last fe.docx
IN C LANGUAGE- I've been trying to finish this program for the last fe.docxIN C LANGUAGE- I've been trying to finish this program for the last fe.docx
IN C LANGUAGE- I've been trying to finish this program for the last fe.docxGordonpACKellyb
 
Data structure circular list
Data structure circular listData structure circular list
Data structure circular listiCreateWorld
 
My C proggram is having trouble in the switch in main. Also the a co.pdf
My C proggram is having trouble in the switch in main. Also the a co.pdfMy C proggram is having trouble in the switch in main. Also the a co.pdf
My C proggram is having trouble in the switch in main. Also the a co.pdfmeerobertsonheyde608
 
Single linked list
Single linked listSingle linked list
Single linked listSayantan Sur
 

Ähnlich wie There are a number of errors in the following program- All errors are.docx (20)

#include iostream #include fstream #include iomanip #.pdf
 #include iostream #include fstream #include iomanip #.pdf #include iostream #include fstream #include iomanip #.pdf
#include iostream #include fstream #include iomanip #.pdf
 
maincpp Build and procees a sorted linked list of Patie.pdf
maincpp   Build and procees a sorted linked list of Patie.pdfmaincpp   Build and procees a sorted linked list of Patie.pdf
maincpp Build and procees a sorted linked list of Patie.pdf
 
Linked lists
Linked listsLinked lists
Linked lists
 
How do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdfHow do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdf
 
Im having trouble figuring out how to code these sections for an a.pdf
Im having trouble figuring out how to code these sections for an a.pdfIm having trouble figuring out how to code these sections for an a.pdf
Im having trouble figuring out how to code these sections for an a.pdf
 
in this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdfin this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdf
 
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdf
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdfTHE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdf
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdf
 
pleaase I want manual solution forData Structures and Algorithm An.pdf
pleaase I want manual solution forData Structures and Algorithm An.pdfpleaase I want manual solution forData Structures and Algorithm An.pdf
pleaase I want manual solution forData Structures and Algorithm An.pdf
 
Getting the following errorsError 1 error C2436 {ctor} mem.pdf
Getting the following errorsError 1 error C2436 {ctor}  mem.pdfGetting the following errorsError 1 error C2436 {ctor}  mem.pdf
Getting the following errorsError 1 error C2436 {ctor} mem.pdf
 
#include iostream#include d_node.h #include d_nodel.h.docx
#include iostream#include d_node.h #include d_nodel.h.docx#include iostream#include d_node.h #include d_nodel.h.docx
#include iostream#include d_node.h #include d_nodel.h.docx
 
C program
C programC program
C program
 
DS Code (CWH).docx
DS Code (CWH).docxDS Code (CWH).docx
DS Code (CWH).docx
 
Circular linked list
Circular linked listCircular linked list
Circular linked list
 
hi i have to write a java program involving link lists. i have a pro.pdf
hi i have to write a java program involving link lists. i have a pro.pdfhi i have to write a java program involving link lists. i have a pro.pdf
hi i have to write a java program involving link lists. i have a pro.pdf
 
I have the following code and I need to know why I am receiving the .pdf
I have the following code and I need to know why I am receiving the .pdfI have the following code and I need to know why I am receiving the .pdf
I have the following code and I need to know why I am receiving the .pdf
 
Write a program that accepts an arithmetic expression of unsigned in.pdf
Write a program that accepts an arithmetic expression of unsigned in.pdfWrite a program that accepts an arithmetic expression of unsigned in.pdf
Write a program that accepts an arithmetic expression of unsigned in.pdf
 
IN C LANGUAGE- I've been trying to finish this program for the last fe.docx
IN C LANGUAGE- I've been trying to finish this program for the last fe.docxIN C LANGUAGE- I've been trying to finish this program for the last fe.docx
IN C LANGUAGE- I've been trying to finish this program for the last fe.docx
 
Data structure circular list
Data structure circular listData structure circular list
Data structure circular list
 
My C proggram is having trouble in the switch in main. Also the a co.pdf
My C proggram is having trouble in the switch in main. Also the a co.pdfMy C proggram is having trouble in the switch in main. Also the a co.pdf
My C proggram is having trouble in the switch in main. Also the a co.pdf
 
Single linked list
Single linked listSingle linked list
Single linked list
 

Mehr von clarkjanyce

The Phoenix Project- Remediation of a Cybersecurity Crisis at the Univ.docx
The Phoenix Project- Remediation of a Cybersecurity Crisis at the Univ.docxThe Phoenix Project- Remediation of a Cybersecurity Crisis at the Univ.docx
The Phoenix Project- Remediation of a Cybersecurity Crisis at the Univ.docxclarkjanyce
 
The percentage of Puerto Rican voters who favored statehood in the Nov.docx
The percentage of Puerto Rican voters who favored statehood in the Nov.docxThe percentage of Puerto Rican voters who favored statehood in the Nov.docx
The percentage of Puerto Rican voters who favored statehood in the Nov.docxclarkjanyce
 
Thermodynamics and Enzymes - List ond describe the vorious common dyna.docx
Thermodynamics and Enzymes - List ond describe the vorious common dyna.docxThermodynamics and Enzymes - List ond describe the vorious common dyna.docx
Thermodynamics and Enzymes - List ond describe the vorious common dyna.docxclarkjanyce
 
The number in the name of a restriction enzyme represents the order in.docx
The number in the name of a restriction enzyme represents the order in.docxThe number in the name of a restriction enzyme represents the order in.docx
The number in the name of a restriction enzyme represents the order in.docxclarkjanyce
 
There are several different methodologies for implementing an ERP syst.docx
There are several different methodologies for implementing an ERP syst.docxThere are several different methodologies for implementing an ERP syst.docx
There are several different methodologies for implementing an ERP syst.docxclarkjanyce
 
There are direct- indirect and non-financial components of compensatio.docx
There are direct- indirect and non-financial components of compensatio.docxThere are direct- indirect and non-financial components of compensatio.docx
There are direct- indirect and non-financial components of compensatio.docxclarkjanyce
 
There are roughly 2000 days from birth until a child begins Kindergart.docx
There are roughly 2000 days from birth until a child begins Kindergart.docxThere are roughly 2000 days from birth until a child begins Kindergart.docx
There are roughly 2000 days from birth until a child begins Kindergart.docxclarkjanyce
 
There are many reasons to become involved with your community- It bene.docx
There are many reasons to become involved with your community- It bene.docxThere are many reasons to become involved with your community- It bene.docx
There are many reasons to become involved with your community- It bene.docxclarkjanyce
 
THEORY OF THE FIRM- MANAGERIAL BEHAVIOR- AGENCY COSTS AND OWNERSHIP ST.docx
THEORY OF THE FIRM- MANAGERIAL BEHAVIOR- AGENCY COSTS AND OWNERSHIP ST.docxTHEORY OF THE FIRM- MANAGERIAL BEHAVIOR- AGENCY COSTS AND OWNERSHIP ST.docx
THEORY OF THE FIRM- MANAGERIAL BEHAVIOR- AGENCY COSTS AND OWNERSHIP ST.docxclarkjanyce
 
Theory of Automata Prove above statement Prove that for any alphabet.docx
Theory of Automata Prove above statement Prove that for any alphabet.docxTheory of Automata Prove above statement Prove that for any alphabet.docx
Theory of Automata Prove above statement Prove that for any alphabet.docxclarkjanyce
 
The NIH is creating a test for the Zika virus- The incidence of a Zika.docx
The NIH is creating a test for the Zika virus- The incidence of a Zika.docxThe NIH is creating a test for the Zika virus- The incidence of a Zika.docx
The NIH is creating a test for the Zika virus- The incidence of a Zika.docxclarkjanyce
 
The National Labor Relations Board is divided into two distinct parts-.docx
The National Labor Relations Board is divided into two distinct parts-.docxThe National Labor Relations Board is divided into two distinct parts-.docx
The National Labor Relations Board is divided into two distinct parts-.docxclarkjanyce
 
The variance of the sample average is Var(Y)-n2- Why-.docx
The variance of the sample average is Var(Y)-n2- Why-.docxThe variance of the sample average is Var(Y)-n2- Why-.docx
The variance of the sample average is Var(Y)-n2- Why-.docxclarkjanyce
 
The urban population in the US grew during the industrial era- Urban g.docx
The urban population in the US grew during the industrial era- Urban g.docxThe urban population in the US grew during the industrial era- Urban g.docx
The urban population in the US grew during the industrial era- Urban g.docxclarkjanyce
 
The value at t-5 of the cash flow stream described in the table below.docx
The value at t-5 of the cash flow stream described in the table below.docxThe value at t-5 of the cash flow stream described in the table below.docx
The value at t-5 of the cash flow stream described in the table below.docxclarkjanyce
 
The U-S- is viewed as a pivotal member in the world economy since its.docx
The U-S- is viewed as a pivotal member in the world economy since its.docxThe U-S- is viewed as a pivotal member in the world economy since its.docx
The U-S- is viewed as a pivotal member in the world economy since its.docxclarkjanyce
 
The triplets are now three and a haif years oid- and Jamie Lee and Ros.docx
The triplets are now three and a haif years oid- and Jamie Lee and Ros.docxThe triplets are now three and a haif years oid- and Jamie Lee and Ros.docx
The triplets are now three and a haif years oid- and Jamie Lee and Ros.docxclarkjanyce
 
The trial balance for Lindor Corporation- a manufacturing company- for.docx
The trial balance for Lindor Corporation- a manufacturing company- for.docxThe trial balance for Lindor Corporation- a manufacturing company- for.docx
The trial balance for Lindor Corporation- a manufacturing company- for.docxclarkjanyce
 
The Town of Bedford Falls approved a General Fund operating budget for.docx
The Town of Bedford Falls approved a General Fund operating budget for.docxThe Town of Bedford Falls approved a General Fund operating budget for.docx
The Town of Bedford Falls approved a General Fund operating budget for.docxclarkjanyce
 
The most common letter is E with 147 occurences- The least common lett.docx
The most common letter is E with 147 occurences- The least common lett.docxThe most common letter is E with 147 occurences- The least common lett.docx
The most common letter is E with 147 occurences- The least common lett.docxclarkjanyce
 

Mehr von clarkjanyce (20)

The Phoenix Project- Remediation of a Cybersecurity Crisis at the Univ.docx
The Phoenix Project- Remediation of a Cybersecurity Crisis at the Univ.docxThe Phoenix Project- Remediation of a Cybersecurity Crisis at the Univ.docx
The Phoenix Project- Remediation of a Cybersecurity Crisis at the Univ.docx
 
The percentage of Puerto Rican voters who favored statehood in the Nov.docx
The percentage of Puerto Rican voters who favored statehood in the Nov.docxThe percentage of Puerto Rican voters who favored statehood in the Nov.docx
The percentage of Puerto Rican voters who favored statehood in the Nov.docx
 
Thermodynamics and Enzymes - List ond describe the vorious common dyna.docx
Thermodynamics and Enzymes - List ond describe the vorious common dyna.docxThermodynamics and Enzymes - List ond describe the vorious common dyna.docx
Thermodynamics and Enzymes - List ond describe the vorious common dyna.docx
 
The number in the name of a restriction enzyme represents the order in.docx
The number in the name of a restriction enzyme represents the order in.docxThe number in the name of a restriction enzyme represents the order in.docx
The number in the name of a restriction enzyme represents the order in.docx
 
There are several different methodologies for implementing an ERP syst.docx
There are several different methodologies for implementing an ERP syst.docxThere are several different methodologies for implementing an ERP syst.docx
There are several different methodologies for implementing an ERP syst.docx
 
There are direct- indirect and non-financial components of compensatio.docx
There are direct- indirect and non-financial components of compensatio.docxThere are direct- indirect and non-financial components of compensatio.docx
There are direct- indirect and non-financial components of compensatio.docx
 
There are roughly 2000 days from birth until a child begins Kindergart.docx
There are roughly 2000 days from birth until a child begins Kindergart.docxThere are roughly 2000 days from birth until a child begins Kindergart.docx
There are roughly 2000 days from birth until a child begins Kindergart.docx
 
There are many reasons to become involved with your community- It bene.docx
There are many reasons to become involved with your community- It bene.docxThere are many reasons to become involved with your community- It bene.docx
There are many reasons to become involved with your community- It bene.docx
 
THEORY OF THE FIRM- MANAGERIAL BEHAVIOR- AGENCY COSTS AND OWNERSHIP ST.docx
THEORY OF THE FIRM- MANAGERIAL BEHAVIOR- AGENCY COSTS AND OWNERSHIP ST.docxTHEORY OF THE FIRM- MANAGERIAL BEHAVIOR- AGENCY COSTS AND OWNERSHIP ST.docx
THEORY OF THE FIRM- MANAGERIAL BEHAVIOR- AGENCY COSTS AND OWNERSHIP ST.docx
 
Theory of Automata Prove above statement Prove that for any alphabet.docx
Theory of Automata Prove above statement Prove that for any alphabet.docxTheory of Automata Prove above statement Prove that for any alphabet.docx
Theory of Automata Prove above statement Prove that for any alphabet.docx
 
The NIH is creating a test for the Zika virus- The incidence of a Zika.docx
The NIH is creating a test for the Zika virus- The incidence of a Zika.docxThe NIH is creating a test for the Zika virus- The incidence of a Zika.docx
The NIH is creating a test for the Zika virus- The incidence of a Zika.docx
 
The National Labor Relations Board is divided into two distinct parts-.docx
The National Labor Relations Board is divided into two distinct parts-.docxThe National Labor Relations Board is divided into two distinct parts-.docx
The National Labor Relations Board is divided into two distinct parts-.docx
 
The variance of the sample average is Var(Y)-n2- Why-.docx
The variance of the sample average is Var(Y)-n2- Why-.docxThe variance of the sample average is Var(Y)-n2- Why-.docx
The variance of the sample average is Var(Y)-n2- Why-.docx
 
The urban population in the US grew during the industrial era- Urban g.docx
The urban population in the US grew during the industrial era- Urban g.docxThe urban population in the US grew during the industrial era- Urban g.docx
The urban population in the US grew during the industrial era- Urban g.docx
 
The value at t-5 of the cash flow stream described in the table below.docx
The value at t-5 of the cash flow stream described in the table below.docxThe value at t-5 of the cash flow stream described in the table below.docx
The value at t-5 of the cash flow stream described in the table below.docx
 
The U-S- is viewed as a pivotal member in the world economy since its.docx
The U-S- is viewed as a pivotal member in the world economy since its.docxThe U-S- is viewed as a pivotal member in the world economy since its.docx
The U-S- is viewed as a pivotal member in the world economy since its.docx
 
The triplets are now three and a haif years oid- and Jamie Lee and Ros.docx
The triplets are now three and a haif years oid- and Jamie Lee and Ros.docxThe triplets are now three and a haif years oid- and Jamie Lee and Ros.docx
The triplets are now three and a haif years oid- and Jamie Lee and Ros.docx
 
The trial balance for Lindor Corporation- a manufacturing company- for.docx
The trial balance for Lindor Corporation- a manufacturing company- for.docxThe trial balance for Lindor Corporation- a manufacturing company- for.docx
The trial balance for Lindor Corporation- a manufacturing company- for.docx
 
The Town of Bedford Falls approved a General Fund operating budget for.docx
The Town of Bedford Falls approved a General Fund operating budget for.docxThe Town of Bedford Falls approved a General Fund operating budget for.docx
The Town of Bedford Falls approved a General Fund operating budget for.docx
 
The most common letter is E with 147 occurences- The least common lett.docx
The most common letter is E with 147 occurences- The least common lett.docxThe most common letter is E with 147 occurences- The least common lett.docx
The most common letter is E with 147 occurences- The least common lett.docx
 

KĂŒrzlich hochgeladen

AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptxiammrhaywood
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSJoshuaGantuangco2
 
Visit to a blind student's school🧑‍🩯🧑‍🩯(community medicine)
Visit to a blind student's school🧑‍🩯🧑‍🩯(community medicine)Visit to a blind student's school🧑‍🩯🧑‍🩯(community medicine)
Visit to a blind student's school🧑‍🩯🧑‍🩯(community medicine)lakshayb543
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfphamnguyenenglishnb
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxMaryGraceBautista27
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management SystemChristalin Nelson
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptxmary850239
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management systemChristalin Nelson
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxAshokKarra1
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptxSherlyMaeNeri
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
HỌC TỐT TIáșŸNG ANH 11 THEO CHÆŻÆ NG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIáșŸT - Cáșą NĂ...
HỌC TỐT TIáșŸNG ANH 11 THEO CHÆŻÆ NG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIáșŸT - Cáșą NĂ...HỌC TỐT TIáșŸNG ANH 11 THEO CHÆŻÆ NG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIáșŸT - Cáșą NĂ...
HỌC TỐT TIáșŸNG ANH 11 THEO CHÆŻÆ NG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIáșŸT - Cáșą NĂ...Nguyen Thanh Tu Collection
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomnelietumpap1
 

KĂŒrzlich hochgeladen (20)

AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
 
Visit to a blind student's school🧑‍🩯🧑‍🩯(community medicine)
Visit to a blind student's school🧑‍🩯🧑‍🩯(community medicine)Visit to a blind student's school🧑‍🩯🧑‍🩯(community medicine)
Visit to a blind student's school🧑‍🩯🧑‍🩯(community medicine)
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptx
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management System
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management system
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptx
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptx
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
HỌC TỐT TIáșŸNG ANH 11 THEO CHÆŻÆ NG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIáșŸT - Cáșą NĂ...
HỌC TỐT TIáșŸNG ANH 11 THEO CHÆŻÆ NG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIáșŸT - Cáșą NĂ...HỌC TỐT TIáșŸNG ANH 11 THEO CHÆŻÆ NG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIáșŸT - Cáșą NĂ...
HỌC TỐT TIáșŸNG ANH 11 THEO CHÆŻÆ NG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIáșŸT - Cáșą NĂ...
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choom
 

There are a number of errors in the following program- All errors are.docx

  • 1. There are a number of errors in the following program. All errors are located in main() and structure definitions. Function declarations and definitions are correct! Locate all errors, fix them (as shown below), run the program and save its output as a comment at the end of the source file. Example: int num = 10; int *ptr; num = &ptr; // <== Error: Comment the line and write the correct line below // Write a short justification where appropriate // num = &ptr; // Error #1 ptr = &num; Name: */ #include <stdio.h> #include <string.h> #include <stdlib.h> #include <time.h> #define DUMMY_TRAILER '177' // octal ASCII code of the // last character in the ASCII table #define NUM_CITIES 10 typedef struct
  • 2. { char name[12]; int temperature[5]; } CITY; // Stack and Queue Node typedef struct node NODE; struct node { CITY city; node *next; }; // Doubly Linked List Node typedef struct d_node D_NODE; struct d_node { CITY city; NODE *forw; NODE *back; }; // Stack Functions NODE *push(NODE *stack, const CITY *pStu); NODE *pop(NODE **stack); // Queue Functions
  • 3. void enqueue(NODE **queue, NODE **rear, const CITY *pStu); NODE *dequeue(NODE **queue, NODE **rear); // Doubly Linked List Functions D_NODE *init_list(void); int insert(D_NODE *list, const CITY *pStu); void traverse_forw(D_NODE *list); void traverse_back(D_NODE *list); // Other Functions void printCity(const CITY *pCity); int main (void) { CITY cList[NUM_CITIES] = { {"Cupertino", {88, 89, 87, 85, 89}}, {"Flagstaff", {81, 80, 88, 89, 89}}, {"Los Angeles", {87, 88, 89, 89, 90}}, {"Philadelphia", {96, 99, 99, 90, 95}}, {"Phoenix", {106, 109, 109, 100, 105}}, {"Portland", {89, 90, 85, 89, 90}}, {"Reno", {108, 105, 109, 100, 108}}, {"Salem", {85, 90, 85, 89, 90}}, {"Tucson", {107, 100, 109, 100, 108}}, {"Yreka", {101, 109, 100, 108, 109}}
  • 4. }; NODE *stack = NULL; NODE *top = NULL; NODE *queue = NULL, *rear = NULL; NODE *front; D_NODE *list; list = init_list(); // build stack and queue with data from an array of CITY structures srand((unsigned int)time(NULL)); int count = rand() % 10; for ( int n = 0; n < count; n++) { int i = rand() % NUM_CITIES; int duplicate = insert(list, &cList[i]); if(duplicate) { // already in the list! push(stack, &cList[i]); enqueue(&queue, &rear, cList[i]); } } // display list printf("nLIST contents (forwards):n");
  • 5. traverse_forw(list); printf("nLIST contents (backwards):n"); traverse_back(list); // display stack if (top) { printf("nSTACK contents from top to bottom:n"); while ((top = pop(stack))) { printCity(top->city); } } else printf ("Empty Stack!n"); // display queue if (front) { printf("nQUEUE contents from front to rear:n"); while ((front = dequeue( queue, rear))) { printCity(front->city); } }
  • 6. else printf ("Empty Queue!n"); return 0; } /*************************************************** Displays the fileds of a CIS_CLASS structure Pre pCls - a pointer to a CIS_CLASS structure Post */ void printCity(const CITY *pCity) { printf("%-20s %3dn", pCity->name, pCity->temperature[0]); } // Stack Functions /*************************************************** Stack Insert: insert in the beginning */ NODE *push(NODE *stack, const CITY *pCity) { NODE *pnew; pnew = (NODE *) malloc(sizeof (NODE)); if (!pnew) {
  • 7. printf("... error in push!n"); exit(1); } pnew->city = *pCity; pnew->next = stack; stack = pnew; return stack; } /*************************************************** Stack Delete: delete the first node */ NODE *pop(NODE **stack) { NODE *first; if (*stack == NULL) return NULL; first = *stack; *stack = (*stack)->next; first->next = NULL; return first; } // Queue Functions /*************************************************** Queue Insert: insert at the end
  • 8. */ void enqueue(NODE **queue, NODE **rear, const CITY *pCity) { NODE *pnew; pnew = (NODE *) malloc(sizeof (NODE)); if (!pnew) { printf("... error in enqueue!n"); exit(1); } pnew->city = *pCity; pnew->next = NULL; if (*queue == NULL) *queue = pnew; else (*rear)->next = pnew; *rear = pnew; return; } /*************************************************** Queue Delete: remove the first node */ NODE *dequeue(NODE **queue, NODE **rear) { NODE *first;
  • 9. if (*queue == NULL) return NULL; first = *queue; *queue = (*queue)->next; if (*queue == NULL) *rear = NULL; first->next = NULL; return first; } // Doubly Linked List Functions /*************************************************** Initialization of a circularly doubly-linked list with one sentinel node */ D_NODE *init_list(void) { D_NODE *list; // allocate the sentinel node list = (D_NODE *) malloc(sizeof (D_NODE)); if (!list) { printf("Error in init_list!n"); exit(1); } list->city.name[0] = DUMMY_TRAILER;
  • 10. list->city.name[1] = '0'; list->forw = list; list->back = list; return list; } /*************************************************** Insert a node in a sorted circularly doubly-linked list with one sentinel node return 1 - if duplicate return 0 - otherwise */ int insert(D_NODE *list, const CITY *data) { D_NODE *curr = list->forw; D_NODE *prev = list; D_NODE *pnew; int duplicate = 1; // search while (strcmp(data->name, curr->city.name) > 0) { prev = curr; curr = curr->forw; }
  • 11. if (strcmp(data->name, curr->city.name) ) { duplicate = 0; // not a duplicate pnew = (D_NODE *) malloc(sizeof (D_NODE)); if (!pnew) { printf("Fatal memory allocation error in insert!n"); exit(3); } pnew->city = *data; pnew->forw = curr; pnew->back = prev; prev->forw = pnew; curr->back = pnew; } return duplicate; } /*************************************************** Traverses forward a circularly doubly-linked list with one sentinel node to print out the contents of each node */ void traverse_forw(D_NODE *list)
  • 12. { list = list->forw; // skip the dummy node while (list->city.name[0] != DUMMY_TRAILER) { printCity(&list->city); list = list->forw; } } /*************************************************** Traverses backward a circularly doubly-linked list with one sentinel node to print out the contents of each node */ void traverse_back(D_NODE *list) { list = list->back; // skip the dummy node while (list->city.name[0] != DUMMY_TRAILER) { printCity(&list->city); list = list->back; } } /* ================= Sample Output #1 ================= */
  • 13. /* LIST contents (forwards): Cupertino 88 Los Angeles 87 Philadelphia 96 Phoenix 106 Reno 108 Tucson 107 LIST contents (backwards): Tucson 107 Reno 108 Phoenix 106 Philadelphia 96 Los Angeles 87 Cupertino 88 STACK contents from top to bottom: Tucson 107 Philadelphia 96 QUEUE contents from front to rear: Philadelphia 96 Tucson 107 */ /* ================= Sample Output #2 ================= */
  • 14. /* LIST contents (forwards): Flagstaff 81 Philadelphia 96 Yreka 101 LIST contents (backwards): Yreka 101 Philadelphia 96 Flagstaff 81 Empty Stack! Empty Queue! */