#ifndef CPP_TESTSTACK2
#define CPP_TESTSTACK2
#include <iomanip>
#include <iostream>
#include <typeinfo>
#include <cstdlib>
usingnamespace std;
// Specification file for a linked list abstract data type class.
// This linked list is actually a stack, since all additions and
// removals are at the head.
template<class type>
struct node // Each node has two fields:
{
type data; // a data field,
node<type> *next; // and a pointer field.
};
template<class type>
class stack
{
private:
node<type> *head; // Pointer to the first cell.
public:
stack();
void push(node<type>*& head, type item);
bool pop(node<type>*& head);
bool search(type item);
void view();
bool empty();
bool full();
};
template<class type>
void stack<type> :: push (node<type>*& head, type item)
{
node<type> *t;
t-> data=item;
t-> next=head;
head = t;
}
// Function to remove the first element from the stack and
// return it to the caller.
template<class type>
bool stack<type> :: pop (node<type>*& head)
{
node<type>* cur;
cur = head;
if(cur == NULL)
{
returnfalse;
}
else
{
head = cur -> next;
delete cur;
returntrue;
}
}
// Accessor functions.
// Function to see whether an element is on the list.
template<class type>
bool stack<type> :: search (type item)
{
node<type>* cur=head;
while(cur != NULL && cur -> data != item)
{
cur=cur -> next;
}
return cur;
}
// Function to output the list for viewing. Assumes the
// data type is compatible with cout << .
template<class type>
void stack<type> :: view ()
{
node<type>* tmp = head;
while(tmp != NULL)
{
cout<< tmp -> data << endl;
tmp = tmp -> next;
}
}
// Is the list empty?
template<class type>
bool stack<type> :: empty ()
{
if(head-> next = NULL)
returntrue;
elsereturnfalse;
}
// Is the list full?
template<class type>
bool stack<type> :: full ()
{
returnfalse;
}
#endif
int main(){
stack<int> a;
a.push(0);
a.push(4);
a.push(3);
a.view();
}
Its a code that takes any data type into a linked list.
Output:
teststack2.cpp: In function ‘int main()’:
teststack2.cpp:114: error: no matching function for call to ‘stack<int>::push(int)’
teststack2.cpp:38: note: candidates are: void stack<type>::push(node<type>*&, type) [with type = int]
teststack2.cpp:115: error: no matching function for call to ‘stack<int>::push(int)’
teststack2.cpp:38: note: candidates are: void stack<type>::push(node<type>*&, type) [with type = int]
teststack2.cpp:116: error: no matching function for call to ‘stack<int>::push(int)’
teststack2.cpp:38: note: candidates are: void stack<type>::push(node<type>*&, type) [with type = int]
Your member function "push" defined on line 38 requires two arguments. One is of your 'node' type, the other is an integer. I see you only passing an integer on lines 114 115 and 116.
we thought that but did not know what to pass in as the node type, that parameter is supposed to pass in the head pointer automatically with out declaring it
@OP: That's not what that does. As a private data member your "head" function is accessible by any member of that class, but it doesn't get passed in by default like that. Delete that part of the function declaration and try accessing "head" as if it were a global variable to that member functions of that class.
we have tried what you all are saying but still no luck... have any of you put it into a compiler and got it to work with the suggestions you all are saying? if u did can u post how you put it in because we may just be typing it in wrong.