Home > Back-end >  C language, chain stack how to exchange any node, not the data domain values of exchange, but the wh
C language, chain stack how to exchange any node, not the data domain values of exchange, but the wh

Time:10-25

Stack, as shown in the topic want to chain of n nodes and m nodes exchange
Can give a complete code

CodePudding user response:

It's easy, isn't it, that is, before and after change the node of before and after the m to n nodes, before and after change the node of before and after n to m nodes,
N_pre - & gt; Next=m;//n before the next node to a node in the point m
TMP=m - & gt; next;//temporary save m next node
M - & gt; Next=n - & gt; next;//m next node points to the next node n
N - & gt; Next=TMP;//n the next node point to the original m next node
M_pre - & gt; Next=n;//m before the next node to a node in the point n
  • Related