Quote:
pls check this errors not able to point out my mistake
First mistake is incorrect indentation of code:
Advice: Learn to indent properly your code, it show its structure and it helps reading and understanding. It also helps spotting structures mistakes.
#include<iostream>
#include<stack>
using namespace std;
void recursion(stack s1, stack s2)
stack < int > s1;
stack < int > s2;
struct node {
int data;
node * next;
};
typedef struct node * lptr;
int main() {
stack < int > s1;
stack < int > s2;
int mp;
cin >> mp;
lptr l1;
int n, m;
while (n != -1)
cin >> n;
s1.push(n);
l1 = new(node);
l1 -> data = n;
l1 -> next = NULL;
lptr l2;
while (m != -1)
cin >> m;
s2.push(m);
l2 = new(node);
l2 -> data = m;
l2 -> next = NULL;
cout << recursion(s1, s2);
return 0;
}
void recursion(stack s1, stack s2) {
if (s1.pop() = s2.pop())
recursion(s1, s2);
cout << s1.pop();
}
Indentation style - Wikipedia[
^]
Best C++ Formatter and Beautifier[
^]
Online C/C++ Formatter, Indenter and Beautifier – Techie Delight[
^]
Professional programmer's editors have this feature and others ones such as parenthesis matching and syntax highlighting.
Notepad++ Home[
^]
ultraedit[
^]
Enabling Open Innovation & Collaboration | The Eclipse Foundation[
^]
-----
Then I suspect some missing "{" cand "}" in your code:
replace
while (n != -1)
cin >> n;
s1.push(n);
l1 = new(node);
l1 -> data = n;
l1 -> next = NULL;
lptr l2;
while (m != -1)
cin >> m;
s2.push(m);
l2 = new(node);
l2 -> data = m;
l2 -> next = NULL;
with
while (n != -1) {
cin >> n;
s1.push(n);
l1 = new(node);
l1 -> data = n;
l1 -> next = NULL;
}
lptr l2;
while (m != -1) {
cin >> m;
s2.push(m);
l2 = new(node);
l2 -> data = m;
l2 -> next = NULL;
}
There is other weird things in your code, but since you did not explain how your code go wrong, it is difficult to say.
A good programming question is:
- source code
- Error message or wrong behavior description.
- Sample input, expected output, actual output