SlideShare a Scribd company logo
1 of 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!
*/

More Related Content

Similar to 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
 

Similar to 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
 

More from 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
 

More from 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
 

Recently uploaded

Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 

Recently uploaded (20)

Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 

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! */