Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report