Suppose that I define the following class:
class example_class{
public:
example_class() ;
void funtion_1();
void function_2();
protected:
struct st {
example_class *next_element;
example_class *prev_element;
} s1;
int variable_1;
double variable_2;
private:
int *variable_3;
}
Then I create four objects:
example_class *A;
example_class *B;
example_class *C;
example_class *D;
And link them togother as a linked list: A-B-C-D.
Then I create a new object E and want to insert E before C.
Below is what I do:
example_class *E;
E->s1.next_elemen t = C;
E->s1.prev_elemen t = B;
C->s1.prev_elemen t = &(E->s1.next_elemet );
B->s1.next_elemen t = &(E->s1.next_elemen t);
Are above operation correct? For the last two sentences, I can also
write:
C->s1.prev_elemen t = E;
B->s1.next_elemen t = E;
I think &(E->s1.next_elemet )= E, am I right?
--------------------------------------
Below is another situation:
I modify the defination of example_class to be:
class example_class{
public:
example_class() ;
void funtion_1();
void function_2();
double new_variable1; //I add two variables
int new_variable2; // in front of the strust st.
protected:
struct st {
example_class *next_element;
example_class *prev_element;
} s1;
int variable_1;
double variable_2;
private:
int *variable_3;
}
After I add two new variables in front of struct st, can I still do
the same operation as above example? That is:
With a linked list: A-B-C-D same as above.
Then I create a new object E and want to insert E before C.
Below is what I do:
example_class *E;
E->s1.next_elemen t = C;
E->s1.prev_elemen t = B;
C->s1.prev_elemen t = &(E->s1.next_elemet );
B->s1.next_elemen t = &(E->s1.next_elemen t):
Are the above operation correct?
With two new variables added in front of struct st, can I still
say that &(E->s1.next_elemet )=E ?
As long as there is variable infront of struct st, I can not
say &(E->s1.next_elemet )=E ?
If possible, please give your correction.
Thanks a lot.
Jack
class example_class{
public:
example_class() ;
void funtion_1();
void function_2();
protected:
struct st {
example_class *next_element;
example_class *prev_element;
} s1;
int variable_1;
double variable_2;
private:
int *variable_3;
}
Then I create four objects:
example_class *A;
example_class *B;
example_class *C;
example_class *D;
And link them togother as a linked list: A-B-C-D.
Then I create a new object E and want to insert E before C.
Below is what I do:
example_class *E;
E->s1.next_elemen t = C;
E->s1.prev_elemen t = B;
C->s1.prev_elemen t = &(E->s1.next_elemet );
B->s1.next_elemen t = &(E->s1.next_elemen t);
Are above operation correct? For the last two sentences, I can also
write:
C->s1.prev_elemen t = E;
B->s1.next_elemen t = E;
I think &(E->s1.next_elemet )= E, am I right?
--------------------------------------
Below is another situation:
I modify the defination of example_class to be:
class example_class{
public:
example_class() ;
void funtion_1();
void function_2();
double new_variable1; //I add two variables
int new_variable2; // in front of the strust st.
protected:
struct st {
example_class *next_element;
example_class *prev_element;
} s1;
int variable_1;
double variable_2;
private:
int *variable_3;
}
After I add two new variables in front of struct st, can I still do
the same operation as above example? That is:
With a linked list: A-B-C-D same as above.
Then I create a new object E and want to insert E before C.
Below is what I do:
example_class *E;
E->s1.next_elemen t = C;
E->s1.prev_elemen t = B;
C->s1.prev_elemen t = &(E->s1.next_elemet );
B->s1.next_elemen t = &(E->s1.next_elemen t):
Are the above operation correct?
With two new variables added in front of struct st, can I still
say that &(E->s1.next_elemet )=E ?
As long as there is variable infront of struct st, I can not
say &(E->s1.next_elemet )=E ?
If possible, please give your correction.
Thanks a lot.
Jack
Comment