Pseudocode description of a function that uses only d and q

Assignment Help Basic Computer Science
Reference no: EM13834906

Suppose you have a deque D containing the numbers (1,2,3,4,5,6,7,8), in this order. Suppose further that you have an initially empty queue Q. Give a pseudo-code description of a function that uses only D and Q (and no other variables or objects) and results in D storing the elements (1,2,3,5,4,6,7,8), in this order.

Here is my C++ code so far, I am getting errors unitialized variable d, and newPtr.

#include "stdafx.h"

# include 
# include 
using namespace std;
/*----------------------------------------------*/
/* TYPES */
typedef int itemtype;
struct node {
struct node * previous;
itemtype item;
struct node * next;
};
typedef struct node node;
struct deque {
node * front; /* pointer to a dummy node. */
node * end; /* pointer to a dummy node. */
int *size;
};
typedef struct deque deque;
/*----------------------------------------------*/
/* PROTOTYPES */
deque newEmptyDeque(void);
int isEmpty(deque d);
void printFrontToEnd(deque d);
void insertAfterInDLL(itemtype i, node * nodePtr); /* auxiliary */
void addToFront(itemtype i, deque d);
void addToEnd(itemtype i, deque d);
itemtype getFront(deque d);
itemtype getEnd(deque d);
itemtype rmFront(deque d);
/*----------------------------------------------*/
int main(void) {
deque d;
d = newEmptyDeque();
printf("%d\n", isEmpty(d));
printf("Here is the deque, front to end: ");
printFrontToEnd(d);
printf(". Listing completed.\n");
addToFront(1, d);
addToFront(2, d);
addToFront(3, d);
addToEnd(4, d);
addToEnd(5, d);
addToEnd(6, d);
printf("Here is the deque, front to end: ");
printFrontToEnd(d);
printf(". Listing completed.\n");
printf("%d\n", isEmpty(d));
printf("%d\n", rmFront(d));
printFrontToEnd(d);
return 0;
}
/*----------------------------------------------*/
deque newEmptyDeque(void)
{
deque d;
d.front = (d.front);malloc(sizeof(node));
d.end = (d.end);malloc(sizeof(node));
d.size = (d.size);malloc(sizeof(int));
*(d.size) = 0;
(d.front)->next = d.end;
(d.front)->previous = NULL;
(d.end)->previous = d.front;
(d.end)->next = NULL;
return d;
}
/*----------------------------------------------*/
int isEmpty(deque d) {
return (d.front)->next == d.end;
}
/*----------------------------------------------*/
void printFrontToEnd(deque d) {
node * aux;
aux = (d.front)->next;
while ((aux->next) != NULL) {
printf("%d ", aux->item);
aux = aux->next;
}
}
/*----------------------------------------------*/
/* Auxiliary function to insert an item after a given node
in a doubly linked list.
*/
void insertAfterInDLL(itemtype i, node * nodePtr) {
node * nextPtr; /* next node after *nodePtr. */
node * newPtr; /* new node. */
nextPtr = nodePtr->next;
newPtr = (newPtr); malloc(sizeof(node));
newPtr->item = i;
nodePtr->next = newPtr;
newPtr->previous = nodePtr;
newPtr->next = nextPtr;
nextPtr->previous = newPtr;
}
/*----------------------------------------------*/
void addToFront(itemtype i, deque d) {
insertAfterInDLL(i, d.front);
*(d.size) = *(d.size) + 1;
}
/*----------------------------------------------*/
void addToEnd(itemtype i, deque d) {
insertAfterInDLL(i, (d.end)->previous);
}
/*----------------------------------------------*/
itemtype getFront(deque d) {
return (d.front)->next->item;
}
itemtype getEnd(deque d) {
return (d.end)->previous->item;
}
itemtype rmFront(deque d) {
itemtype x = (d.front)->next->item;
node * aux;
aux = (d.front)->next->next;
node * z;
z = (d.front)->next;
free(z);
return x;
}

Reference no: EM13834906

Questions Cloud

Analyze an operations process in a local organisation : To briefly describe and analyse an operations process in a local organisation in your country or region, and to explore this process by applying at least one of the core concepts you have learned in this subject.
Discuss set of metrics to use by feets : Using SCOR Level 1, discuss and recommend a set of metrics to use by Feets, the class scenario company. You will want to discuss the effect the metrics you choose will have on the company and the order in which you would implement the metrics
What is the minimum size of sequence number in bits : Suppose that a window size in Selective and Repeat is 4, what is the minimum size of sequence number in bits required to have no problems at receiver.
Improve the security and confidentiality of patient health : he benefits of using information technology are plentiful. For example, the promise of fully realized electronic medical records is having a single record that includes all of a patient's health information: a record that is up to date, complete, ..
Pseudocode description of a function that uses only d and q : Suppose you have a deque D containing the numbers (1,2,3,4,5,6,7,8), in this order. Suppose further that you have an initially empty queue Q. Give a pseudo-code description of a function that uses only D and Q (and no other variables or objects) and ..
How different empires developed in two world culture areas : analyze how two different empires developed in two world culture areas in the premodern world (between the Bronze Age to 1600 CE).
Holly manufacturing case : Holly Manufacturing Company produces two cello models. One is a standard acoustic cello that sells for $600 and is constructed from medium-grade materials. The other model is a custom-made amplified cello with pearl inlays and a body constr..
How would you determine ph of vinegar using cabbage juice : How would you determine the PH of vinegar using cabbage juice as an indicator
Joint stock companies motivate nations to engage exploration : What motivated each group to explore and colonize the New World? How were their motivations similar, how were they different? How did Mercantilism and Joint Stock companies motivate these nations to engage in exploration

Reviews

Write a Review

Basic Computer Science Questions & Answers

  What are the practical benefits

What are the practical benefits, if any, of importing a specific class rather than an entire package (e.g. import java.net.* versus import java.net.Socket)?

  Assembly program to compute division of two integer numbers

Write a program in assembly with the necessary comments that computes division of two integer numbers (Y by X) by consecutively subtracting X from Y.

  Write an xeyes command to display a window

Find and install xeyes (not tuxeyes). Write an xeyes command to display a window that is 600 pixels wide and 400 pixels tall, is located 200 pixels from the right edge of the screen and 300 pixels from the top of the screen.

  How does disaster recovery planning ensure business continui

How does disaster recovery planning ensure business continuity?

  Draw the pipeline execution diagrams

In snippet A, the branch is taken twice and then not taken. In snipped B, first branch is taken once and second branch is also taken once.

  What three functions are the most important

DBMS has many functions. What three functions are the most important and why are they most important?

  Writing a report upon the data and networking needs

Identify an organization and write a report about the organization's data/networking needs and the current LAN use, a current network model with equipment, footage spans, and protocols in use (Topology, Location, Equipment, Protocols).

  Write an output statement that displays the memory location

Write an output statement that displays the memory location of the value 4 stored in intArray[] in base-16 integer format.

  Exploit wildcard feature in order to cheat system

How could Dave, dishonest teller, exploit the wildcard feature  to cheat the system? Dave would want to concentrate on vouchers that are nearly one year old since such vouchers are likely to have been lost.

  Information security management and framework choice

What are the major perspectives to consider in information security management and framework choice

  The discussion and in the assignment tool

Post your response to the following questions in both the discussion and in the assignment tool. Name your assignment in the following manner: LastName_3A

  Changing conditions significant influence on way health

What changing conditions do you think have the most significant influence on way the health information is managed today? Why?

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd