Hello
how do you write a program using a link list for a particular stack that will store data of the type char. Calling a member function named pushing to push an item onto the stack and a member function named popping to pop the item off the stack.
a struct named StackFrame and a pointer named link as well as a typedef statement, a class named Stack , copy constructor, destructor and a bool; empty() method.
You need to prompt for a word from the keyboard and then show the word written backwards, you also need to give the user the chance to try again.
// MY H FILE
#include <iostream>
#include <iomanip>
using namespace std;
//linked list structure
struct Stackframe
{
char data;
Stackframe* next;
void stack::Push(int n)
{
nodetype newNode = new Stackframe; //creating a new node
newNode->data = n; //assigning to the new node
if(is_empty())
{
newNode->next = NULL;
top = newNode;
}//end if
else
{
newNode->next = top;
top = newNode;
}//end else
}//end of push function
void stack::Pop(int & n)
{
if(is_empty())
{
cout<<"The stack cannot be deleted because it is empty"<<endl;
}//end if
else
{
nodetype temp;
temp = top;
top = top -> next;
n = temp->data;
temp ->next = NULL;
delete temp;
}//end else
}//end of pop function
void stack::display()
{
nodetype temp = top;
if(is_empty())
{
cout<<"nothing to display"<<endl;
}//end if
else
{
while(temp != NULL)
{
cout<<temp->data<<endl;
temp = temp->next; //move for next and display so on
}
}//end else
}//end of display funtion
stack::~stack()
{
if(is_empty())
{
cout<<"nothing to destroy";
}//end if
else
{
while(top->next != NULL)
{
nodetype temp;
temp = top;
top = top -> next;
temp ->next = NULL;
delete temp;
}
}//end else
}//end of destructor
END OF IMPLEMENTATION.H
***********************************************************
// INT MAIN FILE . CPP
#include <iostream>
#include <iomanip>
//header file
#include "implementation.h"
using namespace std;
//function prototype
int main()
{
stack mystack;
char word;
cout<<"Please enter a word : ";
cin>>word;
mystack.Push(word);
mystack.display();
return 0;
}//end of main function
this is what i have so far but having trouble with my int main()