Home PC Games Linux Windows Database Network Programming Server Mobile  
  Home \ Programming \ To convert into a binary search tree sorted doubly linked list     - Generated characters using Java Videos (Programming)

- Zabbix monitoring tool deployment under Ubuntu server (Server)

- Configuring s3c-linux- appears Unable to find the QT3 installation (Linux)

- Linux system Iptables Firewall User Manual (Linux)

- CentOS 6.5 install Maven and Nexus warehouse agent (Server)

- Mac OS X Server installation and application (Linux)

- Let Markdown code syntax highlighting and support Django1.6 (Linux)

- Zombie process under Linux (Linux)

- Linux kernel programming parameter passing between modules and function calls (Programming)

- Linux command -nohup & (Linux)

- Simple RPM package production (Linux)

- New features of Java 9 HTTP2 and REPL (Programming)

- Linux --- process handle limit summary (Linux)

- Java memory mechanism Description (Programming)

- Apache Spark1.1.0 deployment and development environment to build (Server)

- Linux how to handle file names that contain spaces and special characters (Linux)

- Oracle 10g New Features - Archive Compression (Database)

- Clojure programming languages: take full advantage of the Clojure plug-in Eclipse (Programming)

- Examples of Python any parameters (Programming)

- Linux bash: scp: command not found the problem (Linux)

  To convert into a binary search tree sorted doubly linked list
  Add Date : 2018-11-21      
  Title: Enter a search tree two yuan, two yuan to find the tree into a sort of two-way linked list. Requirements can not create any new node, adjust the pointers point only.
For example, dibasic search tree
/ \
/ \ / \
Converted into a doubly linked list

4 = 6 = 8 = 10 = 12 = 14 = 16.

Ideas: a lot of problems for the tree, you can use the recursive method to deal with. This question is no exception. Our most basic way of considering this topic.

The right to a binary programming doubly linked list, the final is an ordered sequence, that is, after the results of traversal, then when we use the traversal traverse binary tree traversal to a node, the node is a preamble pointer to the current node, then left pointer points to the preamble of the current node node, then the node so that the preamble refers to the current node.

BinTree * head = NULL;
void helper (BinTree * root, BinTree * & pre)
 if (root == NULL && root == NULL)
 helper (root-> left, pre);
 if (head == NULL)
  head = root;
 if (pre == NULL)
  pre = root;
  root-> left = pre;
  pre-> right = root;
  pre = root;
 // Cout < < root-> value < < "" < < endl;
 helper (root-> right, pre);
BinTree * SearchTreeConverstToList (BinTree * root)
 BinTree * pre = NULL;
 helper (root, pre);
 return head;

Thought two: If the current node, we put the right sub-tree into a doubly linked list, and then left sub-tree into a doubly linked list, when we marked the conversion of the head node and tail node of the list, so we only need to the current node and tail left subtree is connected to the head and right subtree is connected to.

void helper_second (BinTree * root, BinTree * & head, BinTree * & tail)
 if (root == NULL || (root-> left == NULL && root-> right == NULL))
  head = root;
  tail = root;
 BinTree * left_head = NULL;
 BinTree * left_tail = NULL;
 BinTree * right_head = NULL;
 BinTree * right_tail = NULL;
 helper_second (root-> left, left_head, left_tail);
 helper_second (root-> right, right_head, right_tail);

 if (left_head == NULL)
  head = root;
  head = left_head;
  left_tail-> right = root;
  root-> right = left_tail;
 if (right_head == NULL)
  tail = root;
  tail = right_tail;
  root-> right = right_head;
  right_head-> left = root;

BinTree * ConverstToList (BinTree * root)
 BinTree * head = NULL;
 BinTree * tail = NULL;
 helper_second (root, head, tail);
 return head;
- Physical structure and process disk IO (Linux)
- Ubuntu 10.04 to Ubuntu 10.10 Upgrade (Linux)
- Ubuntu 14.04 solved using MyEclipse 10.7 flash back (Linux)
- How Oracle implements random reads from specific combinations (Database)
- 20+ Best Practices article MySQL Performance Optimization (Database)
- Ubuntu iptables prevent IP attacks (Linux)
- Ten to improve the efficiency of the Linux bash tricks (Linux)
- How to protect your eyes automatically adjust the screen brightness on Linux (Linux)
- Fragment Android developers learning to resolve (Programming)
- GitLab issued Merge Request return error 500 when the two solutions log (Linux)
- Matters Oracle 11.2 single instance when connecting ASM need to pay attention and deal with the problem (Database)
- Linux Creating a new user error Creating mailbox file: File exists (Linux)
- Linux System Getting Started Learning: Join cron job in Linux (Linux)
- How to install OpenOffice Ubuntu or Linux Mint (Linux)
- RPM package management under Linux (Linux)
- JavaScript basic types and type conversion (Programming)
- Linux usage in echo (Linux)
- Ubuntu 14.04 compile and install Apache (Server)
- Build and verify MongoDB3.0.7 version (shard + replica) Cluster (Database)
- About the replication of JavaScript (Programming)
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.