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 recursive inversion of single-linked table

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

Share

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

The main content of this article is "how to achieve single-linked table recursive inversion", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to realize the recursive inversion of a single-linked table.

Public class Node {private String name = null; private Node next=null; public Node (String name,Node next) {this.name = name; this.next=next;} / / Recursive reverse node public Node reverse (Node head) {if (head==null | | head.next= = null) {return head;} Node temp = head.next; Node newHead = reverse (head.next); temp.next=head; head.next=null; return newHead } / / traverse the names of all nodes public String getNodeAllName () {String names = ""; Node currNode = this; while (currNodekeeper null) {names + = currNode.name+ "- >"; currNode = currNode.next;} return names;} public static void main (String [] args) {Node nodeC = new Node ("C", null) Node nodeB = new Node ("B", nodeC); Node nodeA = new Node ("A", nodeB); System.out.println (nodeA.getNodeAllName ()); / / reverse A node Node reversedNode = nodeA.reverse (nodeA); System.out.println (reversedNode.getNodeAllName ()) }} at this point, I believe you have a deeper understanding of "how to achieve single-linked table recursive inversion". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

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