c++ program 1-create a program that implements a stack using linked list c++ pro
ID: 3759933 • Letter: C
Question
c++ program 1-create a program that implements a stack using linked list c++ program 1-create a program that implements a stack using linked list
web page coding in HTML includes pairs of what are called "tags": and , and TITLE, H6> and . Tags are surrounded by pointed brackets () and tags that occur in pairs have a forward slash just inside the left bracket of the closing tag. The last tag started must be the first one closed. Using a stack, write a program which takes HTML input and determines whether the tags are properly matched. Note that there are some tags that do NOT have a match-e.g. P, BR>, IMG ..> do not have a matching ending tag. Also, count the number of times each non-ending tag appears in the code- eg. count but do not count Requirements: 1.) Read in the tags that do not have m Read in the tags that do not have matches from a file (assume only the three listed above) and Read in the html from a file and print each line to the screen AND an output file to tag stack or check if opening match tag is on top of the stack. processing 1.) store in a linked list 2.) 3.) Find tags and process (can have more than one in a line) by counting and if a "match" tag adding Read in the html from a file and print each line to the screen AND an output file 4.) If an error occurs print an error message(s) to the screen AND an output file and continue 5.) After html file processed print out to the screen AND an output file an alphabetical list of non- ending tags and the count of the number of times each occurred
Explanation / Answer
#include<iostream>
using namespace std;
// Creating a NODE Structure
struct node
{
int data;
struct node *next;
};
// Creating a class STACK
class stack
{
struct node *top;
public:
stack() // constructure
{
top=NULL;
}
void push(); // to insert an element
void pop(); // to delete an element
void show(); // to show the stack
};
// PUSH Operation
void stack::push()
{
int value;
struct node *ptr;
cout<<"nPUSH Operationn";
cout<<"Enter a number to insert: ";
cin>>value;
ptr=new node;
ptr->data=value;
ptr->next=NULL;
if(top!=NULL)
ptr->next=top;
top=ptr;
cout<<"nNew item is inserted to the stack!!!";
}
// POP Operation
void stack::pop()
{
struct node *temp;
if(top==NULL)
{
cout<<"nThe stack is empty!!!";
}
temp=top;
top=top->next;
cout<<"nPOP Operation........nPoped value is "<<temp->data;
delete temp;
}
// Show stack
void stack::show()
{
struct node *ptr1=top;
cout<<"nThe stack isn";
while(ptr1!=NULL)
{
cout<<ptr1->data<<" ->";
ptr1=ptr1->next;
}
cout<<"NULLn";
}
// Main function
int main()
{
stack s;
int choice;
while(1)
{
cout<<"n-----------------------------------------------------------";
cout<<"nttSTACK USING LINKED LISTnn";
cout<<"1:PUSHn2:POPn3:DISPLAY STACKn4:EXIT";
cout<<"nEnter your choice(1-4): ";
cin>>choice;
switch(choice)
{
case 1:
s.push();
break;
case 2:
s.pop();
break;
case 3:
s.show();
break;
case 4:
return 0;
break;
default:
cout<<"Please enter correct choice(1-4)!!";
break;
}
}
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.