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

answer
Answers: 3

Other questions on the subject: Engineering

image
Engineering, 04.07.2019 18:10, Talos02
Burgers vector is generally parallel to the dislocation line. a)-true b)-false
Answers: 2
image
Engineering, 04.07.2019 18:10, ijohnh14
Shafts are machine elements that are used to a) carry axial loads b) direct shear loads c) transmit power d) rotate at constant speed e) none of the above circular and square shafts subjected to the same torque under the same circum behave a) the same way b) almost the same way
Answers: 2
image
Engineering, 04.07.2019 18:20, safiyabrowne7594
Ahe-xe mixture containing a 0.75 mole fraction of helium is used for cooling electronics in an avionics application. at a temperature of 300 k and atmospheric pressure, calculate the mass fraction of helium and the mass density, molar concentration and molecular weight of the mixture. if the cooling capacity is 10 l, what is the mass of the coolant?
Answers: 3
image
Engineering, 04.07.2019 18:20, mjcbs21
What is the heat treatment of metals? what is the benefit of it? why and how it's useful? answer in details, do not write by hand.
Answers: 3
Do you know the correct answer?
For this problem, using C, you will implement the Deque ADT with a Circularly-Doubly-Linked List wit...

Questions in other subjects:

Konu
Physics, 05.02.2021 02:10
Konu
Mathematics, 05.02.2021 02:10