Click here to Skip to main content
15,211,702 members

C / C++ / MFC

 
GeneralRe: C++ DB : SQLServer : SQLExecute - Insert statement returning Error -2 Pin
jeron119-May-20 11:25
Memberjeron119-May-20 11:25 
GeneralRe: C++ DB : SQLServer : SQLExecute - Insert statement returning Error -2 Pin
SureshBL19-May-20 13:19
MemberSureshBL19-May-20 13:19 
GeneralRe: C++ DB : SQLServer : SQLExecute - Insert statement returning Error -2 Pin
SureshBL19-May-20 13:25
MemberSureshBL19-May-20 13:25 
GeneralRe: C++ DB : SQLServer : SQLExecute - Insert statement returning Error -2 Pin
jeron120-May-20 4:46
Memberjeron120-May-20 4:46 
Questionkernel32.lib Pin
CalinNegru18-May-20 11:10
MemberCalinNegru18-May-20 11:10 
AnswerRe: kernel32.lib Pin
Daniel Pfeffer18-May-20 19:49
professionalDaniel Pfeffer18-May-20 19:49 
GeneralRe: kernel32.lib Pin
CalinNegru19-May-20 0:02
MemberCalinNegru19-May-20 0:02 
QuestionHow is this possible? Pin
Tim ONeil17-May-20 4:47
MemberTim ONeil17-May-20 4:47 
I recently lost out on a great job because I couldn't pass the coding challenge. I was given a header file that I COULD NOT modify, and asked to fill it out with a stack with a linked list backbone. The problem was to reverse stack data (integers) such that nodes 1..4 contained 1, 2, 3, 4, and the output would be 4, 3, 2, 1. I easily wrote this, with one problem: none of the methods in the class signatures contained any output method other than top(), which returned the top node. Everything else was a void method. So I modified the size() method t]such that it output the values of each node.

I believe this is where I failed. The code contained a "node" class with a data member and a pointer to the next node. The stack class had a pop method, a push method, that size method, top, and that's about it. Both were templates. Other than adding a friend class or resorting to dirty pointer tricks, I could not figure out how to display the data members of the node class.

I really don't understand how this is a valid problem to pose.

Here is the header I was given:

#include <cstddef>

#pragma once
//a basic stack class.

//Implement all member functions in the file stack.cpp.
// then add a reasonable set of unit tests, with output, to main.cpp.
//Don't modify stack.h or CMakeLists.txt at all, unless you spot a mistake.

template <class t=""> struct _node
{
T _data;
_node<t>* _next;

_node(const T&, _node<t>*);
~_node();
};

template <class t=""> class stack
{
private:
_node<t>* _head;
size_t _size;

public:
stack();
~stack();

size_t size() const; //return the size of the stack
T& top() const; //return a reference to the top value. Throw an exception if the stack is empty.

void push(const T&); //push a new value onto the stack
void pop(); //remove the top value from the stack. Do nothing if the stack is empty.

void invert(); //reverse the order of the entire stack, so that 1,2,3,4,5 becomes 5,4,3,2,1 and so on.
//Your function should work in the most effecient way you can devise, ideally without allocating any memory on the heap.
};
AnswerRe: How is this possible? Pin
Richard MacCutchan17-May-20 5:31
mveRichard MacCutchan17-May-20 5:31 
GeneralRe: How is this possible? Pin
Tim ONeil17-May-20 5:39
MemberTim ONeil17-May-20 5:39 
GeneralRe: How is this possible? Pin
Richard MacCutchan17-May-20 6:28
mveRichard MacCutchan17-May-20 6:28 
GeneralRe: How is this possible? Pin
Richard MacCutchan17-May-20 22:12
mveRichard MacCutchan17-May-20 22:12 
GeneralRe: How is this possible? Pin
Richard MacCutchan19-May-20 23:55
mveRichard MacCutchan19-May-20 23:55 
AnswerRe: How is this possible? Pin
Mircea Neacsu19-May-20 3:09
MemberMircea Neacsu19-May-20 3:09 
PraiseRe: How is this possible? Pin
Greg Utas19-May-20 3:37
professionalGreg Utas19-May-20 3:37 
GeneralRe: How is this possible? Pin
Richard MacCutchan19-May-20 3:37
mveRichard MacCutchan19-May-20 3:37 
GeneralRe: How is this possible? Pin
Mircea Neacsu19-May-20 3:57
MemberMircea Neacsu19-May-20 3:57 
GeneralRe: How is this possible? Pin
Richard MacCutchan19-May-20 4:16
mveRichard MacCutchan19-May-20 4:16 
GeneralRe: How is this possible? Pin
Mircea Neacsu19-May-20 5:08
MemberMircea Neacsu19-May-20 5:08 
GeneralRe: How is this possible? Pin
Richard MacCutchan19-May-20 5:24
mveRichard MacCutchan19-May-20 5:24 
GeneralRe: How is this possible? Pin
Mircea Neacsu19-May-20 6:07
MemberMircea Neacsu19-May-20 6:07 
GeneralRe: How is this possible? Pin
Richard MacCutchan19-May-20 21:36
mveRichard MacCutchan19-May-20 21:36 
GeneralRe: How is this possible? Pin
Mircea Neacsu20-May-20 2:40
MemberMircea Neacsu20-May-20 2:40 
GeneralRe: How is this possible? Pin
Richard MacCutchan19-May-20 23:22
mveRichard MacCutchan19-May-20 23:22 
GeneralRe: How is this possible? Pin
Mircea Neacsu20-May-20 2:44
MemberMircea Neacsu20-May-20 2:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.