subject
Engineering, 06.05.2020 04:44 maddielr17

For this problem, using C, you will implement the Deque ADT with a Circularly-Doubly-Linked List with a Sentinel. As you know, the sentinel is a special link, does not contain a meaningful value, and should not be removed. Using a sentinel makes some linked list operations easier and cleaner in implementation. This list is circular, meaning the end points back to the beginning, thus one sentinel suffices. Implement all functions with the // FIXME... comments in circularList. c .

circularList. h

#ifndef CIRCULAR_LIST_H
#define CIRCULAR_LIST_H

#ifndef TYPE
#define TYPE double
#endif

#ifndef LT
#define LT(A, B) ((A) < (B))
#endif

#ifndef EQ
#define EQ(A, B) ((A) == (B))
#endif

struct CircularList;

struct CircularList* circularListCreate();
void circularListDestroy(struct CircularList* list);
void circularListPrint(struct CircularList* list);
void circularListReverse(struct CircularList* list);

// Deque interface

void circularListAddFront(struct CircularList* list, TYPE value);
void circularListAddBack(struct CircularList* list, TYPE value);
TYPE circularListFront(struct CircularList* list);
TYPE circularListBack(struct CircularList* list);
void circularListRemoveFront(struct CircularList* list);
void circularListRemoveBack(struct CircularList* list);
int circularListIsEmpty(struct CircularList* list);

#endif

circularListMain. c

#include "circularList. h"
#include

int main()
{
struct CircularList* deque = circularListCreate();
circularListAddBack(deque, (TYPE)1);
circularListAddBack(deque, (TYPE)2);
circularListAddBack(deque, (TYPE)3);
circularListAddFront(deque, (TYPE)4);
circularListAddFront(deque, (TYPE)5);
circularListAddFront(deque, (TYPE)6);
circularListPrint(deque);
printf("%g\n", circularListFront(deque));
printf("%g\n", circularListBack(deque));

circularListRemoveFront(deque);
circularListRemoveBack(deque);
circularListPrint(deque);

circularListReverse(deque);
circularListPrint(deque);

circularListDestroy(deque);

return 0;
}

circularList. c

#include
#include
#include
#include "circularList. h"

// Double link
struct Link
{
TYPE value;
struct Link * next;
struct Link * prev;
};

struct CircularList
{
int size;
struct Link* sentinel;
};

/**
* Allocates the list's sentinel and sets the size to 0.
* The sentinel's next and prev should point to the sentinel itself.
*/
static void init(struct CircularList* list)
{
// FIXME: you must write this
}

/**
* Creates a link with the given value and NULL next and prev pointers.
*/
static struct Link* createLink(TYPE value)
{
// FIXME: you must write this
return NULL;
}

/**
* Adds a new link with the given value after the given link and
* increments the list's size.
*/
static void addLinkAfter(struct CircularList* list, struct Link* link, TYPE value)
{
// FIXME: you must write this
}

/**
* Removes the given link from the list and
* decrements the list's size.
*/
static void removeLink(struct CircularList* list, struct Link* link)
{
// FIXME: you must write this
}

/**
* Allocates and initializes a list.
*/
struct CircularList* circularListCreate()
{
struct CircularList* list = malloc(sizeof(struct CircularList));
init(list);
return list;
}

/**
* Deallocates every link in the list and frees the list pointer.
*/
void circularListDestroy(struct CircularList* list)
{
// FIXME: you must write this
}

/**
* Adds a new link with the given value to the front of the deque.
*/
void circularListAddFront(struct CircularList* list, TYPE value)
{
// FIXME: you must write this
}

/**
* Adds a new link with the given value to the back of the deque.
*/
void circularListAddBack(struct CircularList* list, TYPE value)
{
// FIXME: you must write this
}

/**
* Returns the value of the link at the front of the deque.
*/
TYPE circularListFront(struct CircularList* list)
{
// FIXME: you must write this
return 0;
}

/**
* Returns the value of the link at the back of the deque.
*/
TYPE circularListBack(struct CircularList* list)
{
// FIXME: you must write this
return 0;
}

/**
* Removes the link at the front of the deque.
*/
void circularListRemoveFront(struct CircularList* list)
{
// FIXME: you must write this
}

/**
* Removes the link at the back of the deque.
*/
void circularListRemoveBack(struct CircularList* list)
{
// FIXME: you must write this
}

/**
* Returns 1 if the deque is empty and 0 otherwise.
*/
int circularListIsEmpty(struct CircularList* list)
{
// FIXME: you must write this
return 0;
}

/**
* Prints the values of the links in the deque from front to back.
*/
void circularListPrint(struct CircularList* list)
{
// FIXME: you must write this
}

/**
* Reverses the deque.
*/
void circularListReverse(struct CircularList* list)
{
// FIXME: you must write this
}

ansver
Answers: 3

Another question on Engineering

question
Engineering, 04.07.2019 18:10
The mass flow rate of the fluid remains constant in all steady flow process. a)- true b)- false
Answers: 1
question
Engineering, 04.07.2019 18:10
Refrigerant 134a enters an insulated compressor operating at steady state as saturated vapor at -26°c with a volumetric flow rate of 0.18 m3/s. refrigerant exits at 9 bar, 70°c. changes in kinetic and potential energy from inlet to exit can be ignored. determine the volumetric flow rate at the exit, in m3/s, and the compressor power, in kw.
Answers: 1
question
Engineering, 04.07.2019 18:10
Water at 70°f and streams enter the mixing chamber at the same mass flow rate, determine the temperature and the quality of the exiting stream. 0 psia is heated in a chamber by mixing it with saturated water vapor at 20 psia. if both streams enters the mixing chamber at the same mass flow rate, determine the temperature and the quality of the existing system.
Answers: 2
question
Engineering, 04.07.2019 19:10
An external consultant recommends that a plant installs a bank of capacitors for power factor correction. this will reduce the peak electrical demand charges by an average of 93 kw every month. the plant current pays $13 per kw in peak demand charges. the capacitor bank will include 223 kw of fixed capacitors, and 183 of variable capacitors. the fixed capacitors cost $59 per kw, and the variable capacitors will cost $65 per kw. the consultant charges 21% of the equipment costs to install the capacitors. because this project will reduce the demand for the electric utility, they are prepared to provide a one-time rebate of $42 per kw of reduced demand. what is the simple payback period for this project (in years)?
Answers: 2
You know the right answer?
For this problem, using C, you will implement the Deque ADT with a Circularly-Doubly-Linked List wit...
Questions
question
Mathematics, 02.05.2021 14:00
question
Mathematics, 02.05.2021 14:00
question
Mathematics, 02.05.2021 14:00
question
Social Studies, 02.05.2021 14:00
question
Mathematics, 02.05.2021 14:00
question
Mathematics, 02.05.2021 14:00
Questions on the website: 13722360