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

I\'m looking for help for a C++ program that utilizes stacks/hash tables that ha

ID: 3698431 • Letter: I

Question

I'm looking for help for a C++ program that utilizes stacks/hash tables that has thefollowing algorithm:
The algorithm to determine if thestart and end-tags balance uses a Stack data structure to keeptrack of previously read start-tags. The algorithm is:
1. Readthe input until the beginning of a tag is detected. (i.e. tagsbegin with <: if the next character is a / (slash), then it isan end-tag; otherwise it is a start-tag).
2. Readthe tag's identity. (e.g. both tags <x> and </x> havethe same identity: 'x').
3. Ifthe tag was a start-tag, push it onto the Stack.
4.Otherwise, it is an end-tag. In this case, pop the Stack (whichcontains a previously pushed start-tag identity) and verify thatthe popped identity is the same as the the end-tag just processed.Note: if the stack cannot be popped (because it isempty), the input is invalid; the algorithm should STOP.
5. Ifthe identities do not match, the XML expression isinvalid. STOP.
6. Ifthey do match, then no error has been detected (yet!).
7. Ifthere is still input that has not yet been processed, go back tothe first step.
8. Otherwise (no moreinput) then the input is valid unless the Stack isnot empty. Indicate whether theinput is valid (Stack empty) or invalid and STOP.
Example of XML tags: XML
Valid?
Explanation
<a></a>
Yes
"a" tags balance
<a><b></b></a>
Yes
"a" outer tags and "b" inner tags balance
<a><b></a></b>
No
"a" end-tags does not match start-tag ("b")
<a><b><a></a><b></b></b></a>
Yes
all tags balance
<able><baker></Baker></able>
No
"Baker" end-tag does not matchstart-tag ("baker") (i.e. the tag names arecase-sensitive.)
I'm looking for help for a C++ program that utilizes stacks/hash tables that has thefollowing algorithm:
The algorithm to determine if thestart and end-tags balance uses a Stack data structure to keeptrack of previously read start-tags. The algorithm is:
1. Readthe input until the beginning of a tag is detected. (i.e. tagsbegin with <: if the next character is a / (slash), then it isan end-tag; otherwise it is a start-tag).
2. Readthe tag's identity. (e.g. both tags <x> and </x> havethe same identity: 'x').
3. Ifthe tag was a start-tag, push it onto the Stack.
4.Otherwise, it is an end-tag. In this case, pop the Stack (whichcontains a previously pushed start-tag identity) and verify thatthe popped identity is the same as the the end-tag just processed.Note: if the stack cannot be popped (because it isempty), the input is invalid; the algorithm should STOP.
5. Ifthe identities do not match, the XML expression isinvalid. STOP.
6. Ifthey do match, then no error has been detected (yet!).
7. Ifthere is still input that has not yet been processed, go back tothe first step.
8. Otherwise (no moreinput) then the input is valid unless the Stack isnot empty. Indicate whether theinput is valid (Stack empty) or invalid and STOP.
Example of XML tags: XML
Valid?
Explanation
<a></a>
Yes
"a" tags balance
<a><b></b></a>
Yes
"a" outer tags and "b" inner tags balance
<a><b></a></b>
No
"a" end-tags does not match start-tag ("b")
<a><b><a></a><b></b></b></a>
Yes
all tags balance
<able><baker></Baker></able>
No
"Baker" end-tag does not matchstart-tag ("baker") (i.e. the tag names arecase-sensitive.)
I'm looking for help for a C++ program that utilizes stacks/hash tables that has thefollowing algorithm:
The algorithm to determine if thestart and end-tags balance uses a Stack data structure to keeptrack of previously read start-tags. The algorithm is:
1. Readthe input until the beginning of a tag is detected. (i.e. tagsbegin with <: if the next character is a / (slash), then it isan end-tag; otherwise it is a start-tag).
2. Readthe tag's identity. (e.g. both tags <x> and </x> havethe same identity: 'x').
3. Ifthe tag was a start-tag, push it onto the Stack.
4.Otherwise, it is an end-tag. In this case, pop the Stack (whichcontains a previously pushed start-tag identity) and verify thatthe popped identity is the same as the the end-tag just processed.Note: if the stack cannot be popped (because it isempty), the input is invalid; the algorithm should STOP.
5. Ifthe identities do not match, the XML expression isinvalid. STOP.
6. Ifthey do match, then no error has been detected (yet!).
7. Ifthere is still input that has not yet been processed, go back tothe first step.
8. Otherwise (no moreinput) then the input is valid unless the Stack isnot empty. Indicate whether theinput is valid (Stack empty) or invalid and STOP.
Example of XML tags: XML
Valid?
Explanation
<a></a>
Yes
"a" tags balance
<a><b></b></a>
Yes
"a" outer tags and "b" inner tags balance
<a><b></a></b>
No
"a" end-tags does not match start-tag ("b")
<a><b><a></a><b></b></b></a>
Yes
all tags balance
<able><baker></Baker></able>
No
"Baker" end-tag does not matchstart-tag ("baker") (i.e. the tag names arecase-sensitive.)

Explanation / Answer

executable code

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

//stack defined
char stack[100][15];


//setting top to -1
int top=-1;

//stack push function
void push(char *push_string){

// if stack is full
if(top==100){
printf("Stack is full not able to store more ");
}
else {
//change the value of top
top = top + 1;
strcpy(stack[top],push_string);
}
}


int main()
{
//char input array
char input[100];
printf("Enter the input sring: ");
scanf("%s",input);

//flag values change if the program stops due to invalid syntax
int i=0,flag=0;


//while read throughout the input char array
while(input[i]!=''){
//push string is the string between <> eg; in this <Hi>
//it is push_string ="Hi"
char push_string[10];

//pop string stores string to match with the popped string
char pop_string[10];

//this is for reading the string between<>
//and calling push function
if(input[i]=='<' && input[i+1]!='/'){
//k is for assigning index of push_string
int k=0;
i=i+1;
while(input[i]!='>'){
push_string[k++]=input[i++];
}
push_string[k]='';
push(push_string);
}

//this is for reading string between </ and >
//inside this two invalid condition is check
if(input[i]=='<' && input[i+1]=='/'){
int k = 0;
i=i+2;
while(input[i]!='>'){
pop_string[k++]=input[i++];
}
pop_string[k] = '';

//if the stack is empty then invalid expression
if(top == -1){
flag=1;
break;
}  

//if the identities do not match then stop
if(strcmp(pop_string,stack[top--])!=0){
flag=1;
break;
}
}
  
i++;
}

//flag value is check for valid or invalid xml
if(flag==0)
printf("Syntax is valid ");
else printf("Syntax is invalid ");
  
return 0;
}

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