standard entered on standard input and is not q input string

standard entered on standard input and is not \"q\" input string using recursion, add each alphanumeric character to both a stack and a queue using recursion, pop a character from the stack and dequeue a character from the queue if the characters are not equal output the index of the missmatch followed by std: :endl recursively empty the stack and queue if both the stack and queue are empty output -1 followed by std endl.

Solution

A)

#include<stdio.h>
#include<stdlib.h>
#define bool int
struct sNode
{
char data;
struct sNode *next;
};
void push(struct sNode** top_ref, int new_data);
int pop(struct sNode** top_ref);
bool isEmpty(struct sNode* top);
void print(struct sNode* top);
void insertAtBottom(struct sNode** top_ref, int item)
{
if (isEmpty(*top_ref))
push(top_ref, item);
else
{
int temp = pop(top_ref);
insertAtBottom(top_ref, item);
push(top_ref, temp);
}
}

void reverse(struct sNode** top_ref)
{
if (!isEmpty(*top_ref))
{
int temp = pop(top_ref);
reverse(top_ref);
insertAtBottom(top_ref, temp);
}
}
int main()
{
struct sNode *s = NULL;
push(&s, 4);
push(&s, 3);
push(&s, 2);
push(&s, 1);

printf(\"\ Original Stack \");
print(s);
reverse(&s);
printf(\"\ Reversed Stack \");
print(s);
return 0;
}

bool isEmpty(struct sNode* top)
{
return (top == NULL)? 1 : 0;
}

void push(struct sNode** top_ref, int new_data)
{
struct sNode* new_node =
(struct sNode*) malloc(sizeof(struct sNode));

if (new_node == NULL)
{
printf(\"Stack overflow \ \");
exit(0);
}

new_node->data = new_data;

new_node->next = (*top_ref);
(*top_ref) = new_node;
}
int pop(struct sNode** top_ref)
{
char res;
struct sNode *top;
if (*top_ref == NULL)
{
printf(\"Stack overflow \ \");
exit(0);
}
else
{
top = *top_ref;
res = top->data;
*top_ref = top->next;
free(top);
return res;
}
}
void print(struct sNode* top)
{
printf(\"\ \");
while (top != NULL)
{
printf(\" %d \", top->data);
top = top->next;
}
}

 standard entered on standard input and is not \
 standard entered on standard input and is not \

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site