Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Reflection;
- using System.Xml.Schema;
- namespace ConsoleApp1
- {
- public class Question3
- {
- /*
- A function that build an array y according to maximum between two cells.
- Input: arrX - the array we wish to rebuild into arrayY.
- Output: arrY.
- */
- public static int[] BuildArrY(int[] arrX)
- {
- int[] arrY = new int[arrX.Length];
- int i = 0, totalMax = arrX[0], currentMax = 0;
- for (i = 0; i < arrX.Length - 1; i++)
- {
- if (arrX[i] > totalMax)
- {
- totalMax = arrX[i];
- }
- if (arrX[i + 1] > totalMax) // Won't miss the last index.
- {
- totalMax = arrX[i + 1];
- }
- currentMax = (int) Math.Max(arrX[i], arrX[i + 1]);
- arrY[i] = currentMax;
- }
- arrY[arrY.Length - 1] = totalMax;
- return arrY;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement