Reverse the Words of a String using Stack | C # implementation of the approach ; Function to reverse the words of the given sentence ; Create an empty character array stack ; Push words into the stack ; Get the words in reverse order ; Driver code
using System ; using System . Collections . Generic ; class GFG { static void reverse ( String k ) { Stack < String > s = new Stack < String > ( ) ; String [ ] token = k . Split ( ' ▁ ' ) ; for ( int i = 0 ; i < token . Length ; i ++ ) { s . Push ( token [ i ] ) ; } while ( s . Count != 0 ) { Console . Write ( s . Peek ( ) + " ▁ " ) ; s . Pop ( ) ; } } public static void Main ( String [ ] args ) { String k = " geeks ▁ for ▁ geeks " ; reverse ( k ) ; } }