Inserting Nodes After Q: Let's Double Check!

  • Context: MHB 
  • Thread starter Thread starter evinda
  • Start date Start date
  • Tags Tags
    Nodes
Click For Summary

Discussion Overview

The discussion revolves around the process of inserting a node pointed to by P after a node pointed to by Q in a linked list. Participants explore the implications of using simultaneous assignment notation and the order of operations in both algorithmic and programming contexts.

Discussion Character

  • Technical explanation
  • Conceptual clarification
  • Debate/contested

Main Points Raised

  • Some participants question whether the notation for assignment should be $\rightarrow$ instead of $\leftarrow$ and whether the order of assignments matters.
  • One participant clarifies that the symbol $\leftarrow$ indicates simultaneous assignment, suggesting that the order of operations is not relevant in this context.
  • Another participant expresses concern about the order of operations when writing an algorithm, suggesting that Q->next->prev should be changed before Q->next.
  • It is noted that the order of operations is only critical when writing in a specific programming language like C, while simultaneous assignment can be used in algorithm notation.

Areas of Agreement / Disagreement

Participants generally agree on the meaning of the simultaneous assignment notation, but there is some disagreement regarding the necessity of the order of operations in algorithm writing versus programming.

Contextual Notes

Participants discuss the implications of notation in different contexts (algorithm vs. programming language) and the potential confusion surrounding simultaneous assignments.

evinda
Gold Member
MHB
Messages
3,741
Reaction score
0
Hi! (Smirk)

According to my notes, if we want to insert a node pointed to by P just after node poited to by Q, we have to do the following changements:

$$\begin{pmatrix}
P->prev\\
P->next\\
Q->next\\
Q->next->prev
\end{pmatrix} \leftarrow
\begin{pmatrix}
Q\\
Q->next\\
P\\
P
\end{pmatrix}$$

Shouldn't it be $\rightarrow$ ? :confused:

Also, shouldn't we first change [m]Q->next->prev[/m] and then [m]Q->next[/m]?

Or am I wrong? (Worried)
 
Technology news on Phys.org
evinda said:
Hi! (Smirk)

According to my notes, if we want to insert a node pointed to by P just after node poited to by Q, we have to do the following changements:

$$\begin{pmatrix}
P->prev\\
P->next\\
Q->next\\
Q->next->prev
\end{pmatrix} \leftarrow
\begin{pmatrix}
Q\\
Q->next\\
P\\
P
\end{pmatrix}$$

Shouldn't it be $\rightarrow$ ? :confused:

Also, shouldn't we first change [m]Q->next->prev[/m] and then [m]Q->next[/m]?

Or am I wrong? (Worried)

Hey! (Wave)

The symbol $\leftarrow$ means simultaneous assignment.
It means that we do for instance: [m]P->prev = Q;[/m]. (Smirk)

Since the assignment is simultaneous, the order is not relevant.
You may interpret it as if the right hand values are first copied to 4 temporary variables, and then those 4 temporary variables are copied to the left hand variables. (Nerd)
 
I like Serena said:
Hey! (Wave)

The symbol $\leftarrow$ means simultaneous assignment.
It means that we do for instance: [m]P->prev = Q;[/m]. (Smirk)

Since the assignment is simultaneous, the order is not relevant.
You may interpret it as if the right hand values are first copied to 4 temporary variables, and then those 4 temporary variables are copied to the left hand variables. (Nerd)

A ok... (Nod) But, when we write an algorithm, we have to change firstly [m]Q->next->prev[/m] and then [m]Q->next[/m], right? (Thinking)
 
evinda said:
A ok... (Nod) But, when we write an algorithm, we have to change firstly [m]Q->next->prev[/m] and then [m]Q->next[/m], right? (Thinking)

That is only necessary when you write in an actual programming language like C.
In an "algorithm" you can use this notation for simultaneous assignment. (Nod)
 
I like Serena said:
That is only necessary when you write in an actual programming language like C.
In an "algorithm" you can use this notation for simultaneous assignment. (Nod)

I understand... Thank you! (Smile)
 

Similar threads

  • · Replies 6 ·
Replies
6
Views
3K
Replies
15
Views
5K
Replies
1
Views
2K
  • · Replies 5 ·
Replies
5
Views
1K
  • · Replies 0 ·
Replies
0
Views
2K
  • · Replies 5 ·
Replies
5
Views
1K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 0 ·
Replies
0
Views
6K