Construction of Longest Increasing Subsequence ( LIS ) and printing LIS sequence |  ; int [ ] array = { 10 , 2 , 9 , 3 , 5 , 4 , 6 , 8 } ; int [ ] array = { 10 , 9 , 8 , 6 , 5 , 4 } ; ; Compare previous highest subsequence ; Print list
using System ; using System . Collections . Generic ; class longestIncreasingSubsequence { public static void Main ( String [ ] args ) { int [ ] array = { 10 , 22 , 9 , 33 , 21 , 50 , 41 , 60 , 80 } ; List < int > list = new List < int > ( ) ; List < int > longestList = new List < int > ( ) ; int currentMax ; int highestCount = 0 ; for ( int i = 0 ; i < array . Length ; i ++ ) { currentMax = int . MinValue ; for ( int j = i ; j < array . Length ; j ++ ) { if ( array [ j ] > currentMax ) { list . Add ( array [ j ] ) ; currentMax = array [ j ] ; } } if ( highestCount < list . Count ) { highestCount = list . Count ; longestList = new List < int > ( list ) ; } list . Clear ( ) ; } Console . WriteLine ( ) ; Console . WriteLine ( " The ▁ longest ▁ subsequence " ) ; foreach ( int itr in longestList ) { Console . Write ( itr + " ▁ " ) ; } Console . WriteLine ( ) ; Console . WriteLine ( " Length ▁ of ▁ LIS : ▁ " + highestCount ) ; } }