//****remove at the head, this is stack, push at the head remove at the head.
int character::pop(int num, int success)
{
node *temp; //make a temp pointer

if(head!=NULL) //if the list is not empty
{
temp=head->next; //temp equal to head ->next
delete head; //delete head, remove the first data of the list
head=temp; //now the second data of the list become the first data of the list
return success=1; //return success
}

else
return success=0; //if the list empty return fail

return success;
}

//this function will print from the beginning of the list to the end of the list
void character::print()
{
//if the list was empty print out an error message
if(head==NULL)
{
cout << "There isn't any number" << endl;
return;
}

//else while not the end of the list, print out the number and go to the next one
else
{
cur=head;
while(cur!=NULL)
{
cout << "number: " << cur->num << endl;
cur=cur->next;
}
}
}

//the search function was search from the beginning of the head to the end of the
//head.
int character::search(int num, int success)
{

instead of using the single quotes. That should probably get rid of the errors, or if it doesn't then use:

Code:

(InputChar1.Compare("{") == 0)

09-10-2003

Drew

New Question

A more specific question: Why isn't my program pushing and poping correctly?
Stack program: Develop a stack class using a linked list representation and string data and use it in a program that check C++ programs for the balancing symbols (/* */, ( ), [ ], and { }). The program should read in a C++ program and output one of three messages.

Case 1: Symbol1 does not match symbol2.
Example: “(” does not match “*/”.
Case 2: End of program reached with unmatched symbol.
Example: End of program reached with unmatched “{”.
Case 3: All symbols correctly balanced.

//****remove at the head, this is stack, push at the head remove at the head.
int character::pop(int num, int success)
{
node *temp; //make a temp pointer

if(head!=NULL) //if the list is not empty
{
temp=head->next; //temp equal to head ->next
delete head; //delete head, remove the first data of the list
head=temp; //now the second data of the list become the first data of the list
return success=1; //return success
}

else
return success=0; //if the list empty return fail

return success;
}

//this function will print from the beginning of the list to the end of the list
void character::print()
{
//if the list was empty print out an error message
if(head==NULL)
{
cout << "There isn't any number" << endl;
return;
}

//else while not the end of the list, print out the number and go to the next one
else
{
cur=head;
while(cur!=NULL)
{
cout << "number: " << cur->num << endl;
cur=cur->next;
}
}
}

//the search function was search from the beginning of the head to the end of the
//head.
int character::search(int num, int success)
{