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 basic pc maintenance tasks

What basic PC maintenance tasks or software do you consider to be important for your PC? Please list and describe three maintenance tasks or software and why they are important.Which Windows 7 task manager set of process data selections is the most e..

  Write queries to retrieve data for tsql

Write SQL statements that will retrieve the following data from a database, using Subqueries and Joins. Using the Northwind database, write a SQL SELECT statement that will retrieve the data for the following questions:

  Buffer-overflow attacks

Research and discuss the principle of exploits based on buffer-overflow attacks.

  The wbfk transport company operates throughout mainland

The WBFK Transport Company operates throughout mainland Australia. The company specialize in fast delivery of pallet-loads of goods from one WBFK depot to another WBFK depot. It does not do pickups at a customers premises nor does it deliver door to ..

  Searches of textual documents and database querying

Your company has been hired to design a product that will provide searches of textual documents and database querying. Your design team has not developed a product like this before

  Researchable it topic

Create a reference list of ten scholarly resources in APA format. Also, create an annotated bibliography of the ten scholarly

  Exploring information systems

Exploring information systems

  Create an ou design diagram

Create an OU design diagram. Prepare a graphical representation of the group structure if groups are included in your quantified graphic presentation.

  Create a script that presents a movie guessing game

create a script that presents a Movie guessing game. Allow the users to guess the best picture award from last year. Allow them to guess the word letter-by-letter by entering a character in a form.

  Managing organizational risk

No longer than a decade ago, IT security professionals had to work hard to persuade organizational leaders about the importance of developing effective risk management plans. Nowadays, due to the plethora of cautionary tales that organizations histor..

  What is the value of v_flag

What is the value of v_flag when the following PL/SQL block is executed successfully?

  Receiver r is conducting an auction

Assume the receiver R is conducting an auction in which two bidders each encrypt their bids using the scheme above and send them to R.

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