d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Pseudocode Java
Add Reply New Topic New Poll
Member
Posts: 10,049
Joined: Aug 11 2014
Gold: 540.00
Sep 26 2016 01:15pm
a) Given an array of integers of any size, n ≥ 1, write an algorithm as a pseudo code (not a program!) that would reverse the content of the left half of the array, while leaving the right half intact. If the given array is of an odd size, then the left half is considered to have n/2 + 1 elements. Additionally, your algorithm cannot use any auxiliary storage such as array to perform what is needed.

thank you
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Sep 26 2016 01:23pm
What pseudocode do you already have?
Member
Posts: 10,049
Joined: Aug 11 2014
Gold: 540.00
Sep 26 2016 01:32pm
Quote (carteblanche @ Sep 26 2016 03:23pm)
What pseudocode do you already have?


Code
Algorithm: ReverseLeftHalfOfArray(Array[1..n])

if n % 2 == 0: //Calculates the postion to half.

m := n / 2

else

m := n / 2 + 1

for i := 1 to m/2 do //For the left half.

temp := Array[i] //Exchange the elements accordingly.

Array[i] := Array[m-i]

Array[m-i] := temp


is it correct?
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll