Front and Back Search in unsorted array | C # program to implement front and back search ; Start searching from both ends ; Keep searching while two indexes do not cross . ; Driver Code
using System ; public class GFG { static bool search ( int [ ] arr , int n , int x ) { int front = 0 , back = n - 1 ; while ( front <= back ) { if ( arr [ front ] == x arr [ back ] == x ) return true ; front ++ ; back -- ; } return false ; } static public void Main ( ) { int [ ] arr = { 10 , 20 , 80 , 30 , 60 , 50 , 110 , 100 , 130 , 170 } ; int x = 130 ; int n = arr . Length ; if ( search ( arr , n , x ) ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }