-
undefined reference
The problem with the code is on line 14 and says undefined reference to `push(int)
Code:
#include<iostream>
using namespace std;
void push(int n);
int pop(int &n);
struct elem{
int key;
elem *next;
}*first=NULL,*last=NULL,*p;
int main()
{int n;
cout<<"n=";
while(cin>>n)
push(n);
while(pop(n))
cout<<n<<"";
}
void push(int n,int key)
{p=last;
last=new elem;
last->key=n;
last->next=NULL;
if(p!=NULL)
p->next=last;
if(first==NULL)
last=first;
}
int pop(int &n)
{if(first)
{n=first->key;
p=first;
first=first->next;
if(first==NULL)
last=first;
delete p;
return 1;
}
else return 0;}
-
1. Your indentation is rubbish -> SourceForge.net: Indentation - cpwiki
2. Spot the difference.
void push(int n);
...
push(n);
...
void push(int n,int key)
-
In other words you are trying to use a function that you have not defined.