using System; using System.Collections.Generic; using System.Security.Cryptography.X509Certificates; namespace Csharp { class Program { static int[] Tree = new int[10001]; static void Main(string[] args) { int n = 1; while (true) { var input = Console.ReadLine(); if (input == null || input == "") break; Tree[n] = Convert.ToInt32(input); ++n; } PreToPost(1, n - 1); } static void PreToPost(int node, int bound) { int right = node + 1; while (right <= bound && Tree[right] < Tree[node]) ++right; int left = node + 1; if (left <= right - 1) PreToPost(left, right - 1); if (right <= bound) PreToPost(right, bound); Console.WriteLine(Tree[node]); } } } |