How can i change randomly accessed vector element?

We can use push_back() to push an element at the end of the vector. But if i want to change an element in the middle, i couldn't.

I have made a custom class of 'nodes', and vector mySLL is array of nodes. And i am not able to do:

mySLL[3] = n1;

where n1 is some node. Is there any other way to do it?

Please help.
Thank you!
Is mySLL a std::vector? In that case you code should work if the size of the vector is at least 4.
yes, its a std::vector... So i think i need not worry about the size. But still the node is not getting inserted in 0 position as well using this syntax. Only push_back works...

Following code doesnt work, it doesnt print anything:

#include <iostream>
#include <vector>
#define Null 00


using namespace std;

class node{
public:
int data;
node *next;
};

int main(){

vector <node> mySLL;

node n1;
n1.data = 2;

mySLL[0] = n1;

cout << mySLL[0].data << endl;

return 0;
}
OK, I think i got the it...
Topic archived. No new replies allowed.