Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a routine which will accept a character string as input and determine if i

ID: 3704238 • Letter: W

Question

Write a routine which will accept a character string as input and determine if it is in the form of X l'Cl| Y where X is a string consisting of the letters 'A' and 'B' and Y is the reverse of X. (That is if X 'ABBAB' then Y BABBA'. At each point in the routine you may read only the next character of the string. The C' is the delimiter for 'X' and 'Y') IV. Given a doubly linked list write a routine which will travel through the list adding 10 to every node whose information field is an even number and then travel backwards thru the list subtracting 4 from every node whose information field contains an odd number. V.

Explanation / Answer

Solution:

The below code illustrates with respect to the given data as follows;

It is having the both routines as follows;

#include<iostream>

#include<string.h>

using namespace std;

bool routine1(char *str){

int len = strlen(str);

// First of all String must be of odd length

if(len %2 !=1){

return false;

}

// Defining String X

char *X = new char[((len-1)/2) + 1];

int i=0;

while(str[i] != '/0' && str[i] != 'C' && i<len){

if(str[i] != 'A' && str[i] != 'B'){

   return false;

}

X[i] = str[i];

i++;

}

// Either we have encounter C or end of str

if(i==len){

return false;

}

i++;

// Now we have to see that rest of String must be reverse of X and of equal Size

int xlen = strlen(X);

if(xlen != len-i){

return false;

}

while(str[i] != '/0' && i<len){

if(str[i] != 'A' && str[i] != 'B'){

   return false;

}

if(str[i] != X[xlen-1]){

   return false;

}

i++;

xlen--;

}

return true;

}

struct Node{

int data;

Node *next;

Node *prev;

};

void routine2(Node *root){

Node *current = root;

Node *tail;

// traverse throught he list and add 10 to every node with even data and keep track of tail also

while(current != NULL){

if(current->data %2==0){

   current->data = current->data + 10;

}

current = current->next;

tail = current;

}

// Now tail points to the last Node

while(tail != NULL){

if(tail->data %2 == 1){

   tail->data = tail->data -4;

}

tail = tail->prev;

}

}

int main(){

cout<<"result: " <<routine1("ABBABCBABBA");

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote