Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2015
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.24 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Problem_03
  6. {
  7.     class Program
  8.     {
  9.         static void Main()
  10.         {
  11.             int[] numbers = { 1, 3, 4, 5, 1, 0, 5 };
  12.  
  13.             for (int i = 0; i < numbers.Length; i++)
  14.             {
  15.                 Console.WriteLine(IsBiggerThanNeighbours(numbers, i));
  16.             }
  17.         }
  18.  
  19.         static bool IsBiggerThanNeighbours(int[] testArr, int testPosition)
  20.         {
  21.             bool isBigger = false;
  22.             if(testPosition == 0)
  23.             {
  24.                 if (testArr[testPosition] > testArr[testPosition + 1])
  25.                 {
  26.                     isBigger = true;
  27.                 }
  28.             }
  29.             else if(testPosition == testArr.Length-1)
  30.             {
  31.                 if (testArr[testPosition] > testArr[testPosition - 1])
  32.                 {
  33.                     isBigger = true;
  34.                 }
  35.             }
  36.             else
  37.             {
  38.                 if (testArr[testPosition] > testArr[testPosition - 1] && testArr[testPosition] > testArr[testPosition + 1])
  39.                 {
  40.                     isBigger = true;
  41.                 }
  42.             }
  43.            
  44.  
  45.             return isBigger;
  46.         }
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement