Download Image picture description and more Study notes Digital Logic Design and Programming in PDF only on Docsity!
all] al2] al3]oaf4] all 5] LEE After Reverse | 9 : โ Figure 1.6(b) oa ยซ= a{5] (Swap element 5 value with element 1 value) al2\ 2 al4] Pa va see the suffixes/subscripts on left hand ane eae cae suffixes /subscripts on right hand side are in decreasing order. ( A re is a yy ; st 1 For determining the reverse-array subscript values, we can PSS iginal array. | where โnโ is total number of elements an โiโ is the subscript of the element 7 Bie oe n-i+l ; / , eth! as toa 5-141=5 ee <= cn he st 5-2+ 1=4 YP hi (ned Ba 5 wx wie 5-3+1=3 : gi paeniae : % LAr} wh Jar O48 tah Swapping the values of that elements in the array would thus be reversed. โes To exchange the values of the elements of the array, we need one temporary variabl Then we do the swapping as given below: โ. temp =al[i] a{i] =a[n -i+ 1) aln -i+ 1] =temp Algorithm 1. Begin 2. Get the values and store them in an arr where n is the number of elements. 3. Compute r, 1/2. 4. Exchange the i element with [n - i + 1 temp =al[i] ay with elements a[1], a[2], a[3. } the number of exchange needed to reverse the ar a ] using | โ ali] =a[n -i+ 1] a[n-it+l=temp 5. Carry step 4, r times increasing i by 1. โa Fy