I know there's a lot of guys here that know c++ very well. I think I'm asking a simple question, but I can't get this done. How do I writte a constructor with "initializer_list" in my LinkedStack class? I just want to "push()" each element and point the "front" pointer to the first element.
Thank you in advance!
I know there's a lot of guys here that know c++ very well. I think I'm asking a simple question...
First pic is the method: I think I should iterate and add each element, also point to the first one.
This second pic is how the function should be called from the main()
please help, I know this must be very simple but I've never used this "initializer_list" thing ever
pls halp
pls guys
>>>/sqt/
>>>/stackexchange/
>>>/sage/
>initializer_list
Try writing
LinkedStack stack {1, 2, 3, 4, 5, 6, 7, 8};
Instead
Also paste your code in here, IN FULL using
[ code ] (remove spaces)
Or fuck off. I know how to fix it but I won't tell you until you do so.
I've tried that. The problem is the code in the function, I don't know what to write (that "for" is not correct at all I'm sure).
Ok, I will do that now
[#ifndef NODE_H
#define NODE_H
using namespace std;
template
class Node {
public:
//constructor sense parametres, l'element sera l'enter 0
Node(){
//element= NULL; // NULL?????????????????????
next=nullptr;
}
//constructor amb parametre
Node(T elem) {
element=elem;
next= nullptr;
}
//retorna l'element que hi ha guardat al node
const T& getElement() const{
return element;
}
//retorna un punter al següent node o si no hi ha retorna nullpointer
Node *getNext() const{
return next;
}
//modifica l'adreça de next per la del paràmetre
void setNext(Node *nod){
next = nod;
}
private:
T element;
Node *next;
};
#endif /* NODE_H */]
template
class LinkedStack {
public:
//constructor sense parametres
LinkedStack() {
numElem = 0;
front = nullptr;
}
LinkedStack(std::initializer_list elements){
front = nullptr;
numElem = elements.size();
for(int i=0; i
Please help. I just need to know how to make that constructor with "initializer_list"
Please man, I did what you said
I implore you
PLEASE
I hope you get fired and sent back to your designated shitting streets.
I'm a student, and not indian.
Please man, help me out. It's just that initializer_list thing
If you don't know the material, you don't deserve to pass your final.
Better luck next semester.
I know very well all that pointer stuff and every class. My problem is the initializer_list, no one has explained that to me, and the online examples I've found are unreadable
Do you really need to use initializer_list? Seems like yet another completely unnecessary feature. Use it somewhere and the next guy will be scratching his head for a day thinking what is going on here.
PLOS HALP
Yes, I have to for this asignment..
Do you know how it's used? Or at least where should I look to learn how to use it?
I'm lost af and I haven't found any usefull website
ok here's a hint
the bug is between 12 and 14
come on man, I'm just trying to learn, be good to me
What country?
>push(elements[1]);
Spain
I know that's wrong. How should it be done?
>Catalan
Gross
You don't really know it seems. What you want is push every element of the initializer list into your stack, so you have to use i as an index, that's the variable you increase every turn of the loop.
Using 1 just picks the second item of the list repeatedly, and crashes if there are none.
...