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 flip python binary tree

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

This article shows you how to flip the python binary tree, the content is concise and easy to understand, it will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

Flip a binary tree.

Example:

Enter:

4 / 2 7 / 1 3 6 9

Output:

4 /\ 7 2 /\ 9 6 3 1

The problem in the previous issue is: 160, using queues to implement the stack

1class MyStack {

2 private Queue que

three

4 public MyStack () {

5 que = new LinkedList ()

6}

seven

8 public void push (int x) {

9 que.offer (x)

10 for (int I = 0; I < que.size ()-1; + + I) {

11 que.offer (que.poll ())

12}

13}

fourteen

15 public int pop () {

16 return que.poll ()

17}

eighteen

19 public int top () {

20 return que.peek ()

21}

twenty-two

23 public boolean empty () {

24 return que.isEmpty ()

25}

26}

The offer method stores x at the end of the que. Because the queue is first-in, first-out, and the stack is first-in, first-out, so here push will first store x to the end of the queue, and then put the previous one out of the queue and then rejoin the queue.

The above content is how to flip the python binary tree. Have you learned the knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are 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

Internet Technology

Wechat

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

12
Report