void push(int x) {
s1.push(x);
while(!s1.empty()){
s2.push(s1.top());
s1.pop();
}
s1 = s2;
while(!s2.empty()){
s2.pop();
}
}
Look at the above function. I am implementing queue using stack. While running this, I am getting the following error
Line 176: Char 16: runtime error: reference binding to misaligned address 0xbebebebebebec0ba for type ‘int’, which requires 4 byte alignment (stl_deque.h)
0xbebebebebebec0ba: note: pointer points here
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/bits/stl_deque.h:181:16
Could anyone please tell what’s wrong with the code ?
I expected the above stack to function like a queue.