Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize the movement of linked list nodes in C language

Shulou Source: shulou.com Published: 2022-06-02 02:18:14 09月22日 Update

Editor to share with you how the C language to achieve the movement of linked list nodes, I believe that most people do not know much about it, so share this article for your reference, I hope you will learn a lot after reading this article. Let's learn about it!

# include

# include

# define N 9

Typedef struct node {

Int data

Struct node * next

} ElemSN

ElemSN * Createlink (int a []) {/ / reverse create an one-way linked list

Int i

ElemSN * h=NULL, * p

For (iPhoto: I > = 0; iMub -) {

P = (ElemSN *) malloc (sizeof (ElemSN))

P-> data = a [I]

P-> next=h

Hexamp

}

Return h

}

Void Printlink (ElemSN * h) {

ElemSN * p

For (pairhtern, ptinct, pindup-> next)

Printf ("% 2d\ n", p-> data)

}

ElemSN* MoveMaxnodeToTail (ElemSN*h) {

ElemSN * Pmax,* pje * Qmax,* Q

Pmax=h

For (qaccounhmage pamphlet-> next;p;q=p,p=p- > next) {

If (Pmax- > datadata) {

Pmax=p

Qmax=q

}

} / / for loop p equals null,q as the tail node, Pmax maximum node, the last node of Qmax maximum node

If (Pmax- > next) {/ / determine whether the maximum node is a tail node

If (Pmaxthreshold node) / / determine whether the maximum node is a header node.

Qmax- > next=Pmax- > next; / / broken link

Else

H-> next; / / is the head node, and the pointer h of the head node moves backward

Pmax- > next=q- > next; / / key operation: if the next of the maximum node is not given to NULL (Q-> next equals NULL), the secondary chain is located in the one-way circular linked list.

Q-> next=Pmax;// maximum value is hung to the tail node

}

Return h

}

Int main (void) {

Int a [] = {9, 3, 5, 8, 4, 7, 7, 2, 6, 1}

ElemSN * head

Head=Createlink (a par 9)

Head=MoveMaxnodeToTail (head)

Printlink (head)

}

These are all the contents of the article "how to move linked list nodes in C language". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Node maximum maximum article language mobile content one-way not much key most chain pointer more knowledge industry information information channel channel previous Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Docker Xiaomi MariaDB Shulou Tech Info