Question

Modify the below code to fit the above requirements:

struct node

{

char data;

struct node *next;

struct node *previous;

} *front, *MyNode, *rear, *MyPointer, *anchor *Valuenode ;

typedef struct node node;

int Push(char input)

{

if(IsFull()==1)

{  

printf("The queue is full. Enter the ‘^’ character to stop.\n");

return -1;

}

else if (IsFull()==-1)

{

node *MyNode=(node*)malloc(sizeof(node));

MyNode->data=input;

rear->next=MyNode;

MyNode->previous=rear;

MyPointer=rear=MyNode;

return 1;

}

else

{

node *MyNode=(node*)malloc(sizeof(node));

node *anchor=(node*)malloc(sizeof(node));

MyNode->data=input;

MyPointer=rear=front=MyNode;

MyNode->previous=NULL;

MyNode->next=NULL;

anchor->next=MyNode;

return 0;

}

}

char Pull()

{

char output = 0 ;

char pnull = 0;

if (IsFull()==0)

{  

return pnull;

}

else

{   

output= front->data;

front=front->next;

}

return output;

}

char Pullback()

{

char output = 0 ;

char pullbacknull = 0;

if (IsFull()==0)

{  

return pullbacknull;

}

else

{   

output= front->data;

rear=rear->next;

}

return output;

}

char Front()

{

char fnull = 0 ;

if (IsFull()==0)

{  

return fnull;

}

else

{   

return front->data;

}

}

char Back()

{

char rnull = 0 ;

if (IsFull()==0)

{  

return rnull;

}

else

{   

return rear->data;

}

}

int IsFull()

{

node* temp=(node*)malloc(sizeof(node));

if (front == NULL)

{

return 0;

}

else if (temp==NULL)

{

return 1;

}

  

else

{

return -1;  

}   

}

int Getnext(int choice)

{

if (choice==1)

{

if (MyPointer->previous==NULL)

{

return 0;

}

else

MyPointer=MyPointer->previous;

}

else

{

if (MyPointer->next==NULL)

{

return 0;

}

else

MyPointer=MyPointer->next;

}

return 1;

}

struct node * GetCurrent()

{

return MyPointer;

}

void Reset(int choice2)

{

if (choice2 ==0)

{

MyPointer->next=rear;

}

else

{

MyPointer->next=front;

}

}   

int Delete()

{

if (MyPointer!=NULL)

{

free(MyPointer);

return 1;

}

else   

{   

return 0;

}

}

// New Functions

void InsertAfter(node* MyPointer, char data)

{

Valuenode->previous=MyPointer;

Valuenode->data=data;

}

void DeleteNode(node* MyPointer)

{

if MyPointer->next!=anchor

{free(Valuenode)}

}

void FindValue(char value)

{

  

}

int main() //Queue does end up the IsFull function unlike the Top function in a stack

{

front=(node*)malloc(sizeof(node));

rear=(node*)malloc(sizeof(node));

Valuenode=(node*)malloc(sizeof(node));

MyPointer=(node*)malloc(sizeof(node));

front=NULL;

rear=NULL;

valuenode=NULL;

MyPointer=NULL;

printf("Please input character string:");

while ((input=fgetc(stdin))!='^')

{

if (isalpha(input)||isdigit(input))

Push(input);

}

Print(); //Calls print function

printf("Is pointer deleted? %d\n",Delete());

  

return 0;

};

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Trnferenting the first tue functitno: Srnuorure ケt.run/足 ー1//Lnanrint after a gium Tura hudud ะ nrUL.phr-nentti

Add a comment
Know the answer?
Add Answer to:
Modify the below code to fit the above requirements: struct node { char data; struct node...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • struct Node * new_11( void ) { // return a new node to be the list...

    struct Node * new_11( void ) { // return a new node to be the list anchor struct Node * node = (struct Node *) malloc(sizeof(struct Node)); memset(node, o, sizeof(struct Node)); return node ; struct Node * find_l1(struct Node * anchor, char * word) { // given a pointer to the anchor of the list, and a word, search // the list for the word. return the pointer to the with the word, if found, 7/ or NULL if not...

  • In c++, what alternative to malloc line? Such as struct Node* newNode(int data) { struct Node*...

    In c++, what alternative to malloc line? Such as struct Node* newNode(int data) { struct Node* node = (struct Node*) malloc(sizeof(struct Node)); node->data = data; node->left = NULL; node->right = NULL;    return node; }

  • can someone please double check my code here are the requirements please help me fulfill the...

    can someone please double check my code here are the requirements please help me fulfill the requirements Using the material in the textbook (NumberList) as a sample, design your own dynamic linked list class (using pointers) to hold a series of capital letters. The class should have the following member functions: append, insert (at a specific position, return -1 if that position doesn't exist), delete (at a specific position, return -1 if that position doesn't exist), print, reverse (which rearranges...

  • PROBLEM: string CBQueue::dequeue( ) This method should remove and return the item at the front of...

    PROBLEM: string CBQueue::dequeue( ) This method should remove and return the item at the front of the queue- please add comments EXISTING CODE: #include // this allows you to declare and use strings #include using namespace std; struct qNode {   string data;   qNode* next;   qNode* prev; }; class CBQueue {   public:     CBQueue(); int CBQueue::getSize( ); bool CBQueue::isEmpty( );   private:     qNode* front;     qNode* rear;     int size; }; #include "CBQueue.h" CBQueue::CBQueue() { front = NULL; rear = NULL; size = 0; }...

  • Programming in C: I am trying to modify this linked list to be doubly linked list....

    Programming in C: I am trying to modify this linked list to be doubly linked list. I’m also trying to add a print in reverse function. I’m really struggling with how to change the insert function to doubly link the nodes without effecting the alphabetical sorting mechanism. Example of desired output: Enter your choice: 1 to insert an element into the list. 2 to delete an element from the list. 3 to end. ? 1 Enter a character: a The...

  • need this updated so it will delete the list and then recreate it again /***********************************************************/ /*...

    need this updated so it will delete the list and then recreate it again /***********************************************************/ /* Header files. */ /***********************************************************/ #include <stdio.h> #include <stdlib.h> #include <string.h> /***********************************************************/ /* Structure definitions. */ /***********************************************************/ struct node { int data; struct node *right; struct node *left; }; struct trash { struct node *node; struct trash *next; }; /****************************************/ /* BUILD_LIST. */ /****************************************/ void BUILD_LIST(int number2Add, struct node *(*head), struct node *(*tail)) { int i; struct node *previous, *current; *head = NULL; *tail =...

  • Please rewrite this function using recursive function #include using namespace std; struct Node { char ch;...

    Please rewrite this function using recursive function #include using namespace std; struct Node { char ch; Node* next; }; class LinkedList { Node* head; public: LinkedList(); ~LinkedList(); void add(char ch); bool find(char ch); bool del(char ch); friend std::ostream& operator<<(std::ostream& out, LinkedList& list); }; LinkedList::LinkedList() { head = NULL; } LinkedList::~LinkedList() { Node* cur = head, * tmp; while (cur != NULL) { tmp = cur->next; delete cur; cur = tmp; } } void LinkedList::add(char ch) { Node* cur = head,...

  • A linked list is constructed of nodes described by the following structure: struct node{ char data;...

    A linked list is constructed of nodes described by the following structure: struct node{ char data; struct node *next; }; Assume a linked list containing a sentinel node is constructed from the above nodes. Write a function named "count"-prototyped as int count(struct node*sent)- that accepts a pointer to the sentinel node; counts the number of data (non-sentinel) nodes containing the character 'A'; and returns that count as the function value.

  • This is a code for linked list, it is about adding a node in the middle...

    This is a code for linked list, it is about adding a node in the middle of a list, I am really confused why int i = 2? can't it be 0? Add to the Middle • Allocate memory and store data for new node Traverse to node just before the required position of new node Change next pointers to include new node in between struct node *newNode; newNode = malloc(sizeof(struct node)); newNode->data = 4; struct node *temp head; for(int...

  • Hi, I need to make a program in C that reads the type of currency and...

    Hi, I need to make a program in C that reads the type of currency and organizes them into stacks based on currency which can be read back. This is what I have so far, can I get help finishing it? #include <stdio.h> #include <stdlib.h> const float POUND = 1.31; const float YEN = 0.0091; const float RUPEE = 0.014; const float EURO = 1.11; char c; int currValue; float exchangeValue; float finValue; int printValue; struct node {    int...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT