Question: Can someone finish the program? I need to use Doubly Linked List. I need a C++ program that checks to see if parentheses (or brackets)
Can someone finish the program? I need to use Doubly Linked List. I need a C++ program that checks to see if parentheses (or brackets) in
expressions are valid or not. The program takes as input a text file that has a series
of expressions, one per line. An example input file could be:
[ ][ ][ ][ ]
( )
( try )
]
ok
{
((())) [][][]
[ ] [ ]
55 5 4 3 2 2 { ( [ (3 * 4 ) ] ( 8 + 1 ) ) }
)()(
hello
last
The program should read them in and determine if the brackets are arranged in a
valid way or not. The output should be a summary of the data file with the following
lines:
Statistics:
12 total lines.
8 valid lines.
4 invalid lines.
67% valid.
33% invalid.
As you can see from the example, a line is valid if it has no brackets, if it has brackets
of any kind, they must be nested properly, beginning with an open bracket ( or [ or {
and ending with a closed bracket } or ] or ) respectively. It is not enough to simply
count brackets as the following line is not valid:
( [ ) ]
despite it having the correct number of brackets, and the openings occurring before
the closings.
Here is my Code:
#include "l_char_stack.h"
using namespace std;
int main() { l_char_stack stack; return 0; }
--------------- l_char_stack.h --------------
#include "l_char_stack.h"
l_char_stack::l_char_stack()
{
}
l_char_stack::l_char_stack(int mSize)
{
}
l_char_stack::~l_char_stack()
{
}
void l_char_stack::push(listObjType newItem)
{
}
listObjType l_char_stack::pop()
{
listObjType a;
a = listObjType();
return a;
}
listObjType l_char_stack::peek()
{
listObjType a;
a = listObjType();
return a;
}
bool l_char_stack::isEmpty()
{
return false;
}
bool l_char_stack::isFull()
{
return false;
}
void l_char_stack::clear()
{
}
int l_char_stack::depth()
{
return 0;
}
-------- l_char_stack.h --------
#include "char_linked_list.h"
class l_char_stack
{
private:
public:
l_char_stack();
l_char_stack(int mSize);
~l_char_stack();
void push(listObjType newItem);
listObjType pop();
listObjType peek();
bool isEmpty();
bool isFull();
void clear();
int depth();
};
--------char_linked_list.cpp-----------
#include "char_linked_list.h"
struct ListNode;
char_linked_list::char_linked_list()
{
}
char_linked_list::char_linked_list(const char_linked_list & aList)
{
}
char_linked_list::~char_linked_list()
{
} // end destructor
int char_linked_list::getLength() const
{
return 0;
}
bool char_linked_list::insert(int index, const listObjType & newItem)
{
return false;
}
bool char_linked_list::isEmpty() const
{
return false;
}
bool char_linked_list::remove(int index)
{
return false;
}
bool char_linked_list::retrieve(int index, listObjType & dataItem)
{
return false;
}
char_linked_list::ListNode *char_linked_list::find(int index)
{
return nullptr;
}
---------- char_linked_list.h -----------
typedef char listObjType;
class char_linked_list
{
private:
struct ListNode
{
listObjType item;
ListNode *next;
ListNode *previous;
};
int size;
ListNode *find(int index);
ListNode *head;
public:
char_linked_list();
char_linked_list(const char_linked_list &aList);
~char_linked_list();
int getLength() const;
bool insert(int index, const listObjType& newItem);
bool isEmpty() const;
bool remove(int index);
bool retrieve(int index, listObjType& dataItem);
};
----------- text input file---------------
() [] [[[]]] a b c d e )()()()( (())(())(a)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
