Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using BiggerNeighbor;
- class FindFirstBiggerNeighbor
- {
- public static int sign = 0;
- public static int ValidPosition(int[] elements, int position)
- {
- if (position + 1 < elements.Length && position - 1 >= 0)
- {
- return 1;
- }
- else if (position + 1 == elements.Length)
- {
- return 2;
- }
- else
- {
- return 3;
- }
- }
- public static bool BiggerCheck(int[] elements, int position)
- {
- sign = ValidPosition(elements, position);
- if (sign == 1 && elements[position] > elements[position - 1] && elements[position] > elements[position + 1])
- {
- return true;
- }
- else if (sign == 2 && elements[position] > elements[position - 1])
- {
- return true;
- }
- else if (sign == 3 && elements[position] > elements[position + 1])
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- static void Main()
- {
- int[] array = { 10, 2, 3, 4, 5, 6, 7, 8, 6 };
- for (int i = 0; i < array.Length; i++)
- {
- int index = i;
- bool checkBool = BiggerCheck(array, index);
- if (sign == 1 && checkBool == true)
- {
- Console.WriteLine("{0} is bigger than {1} and {2}", array[index], array[index - 1], array[index + 1]);
- Environment.Exit(0);
- }
- else if (sign == 2 && checkBool == true)
- {
- Console.WriteLine("{0} is bigger than {1} and (empty)", array[index], array[index - 1]);
- Environment.Exit(0);
- }
- else if (sign == 3 && checkBool == true)
- {
- Console.WriteLine("{0} is bigger than (empty) and {1}", array[index], array[index + 1]);
- Environment.Exit(0);
- }
- }
- Console.WriteLine("-1, no such element");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement