Write a void method Shift that takes three parameters A, p, d.
A is an array, p is the number of positions and d is the direction (L = left, R = right). The method should shift the contents of A p positions in the d direction.
(B) To test your method, write a program that reads an array of 10 elements then calls Shift twice and prints the array after each call.
Example:
Enter 10 elements of array A:
17 11 12 15 18 19 20 23 28 39
Enter Shift direct L
Enter number of positions 3
Array After Shift 15 18 19 20 23 28 39 0 0 0
Enter Shift direct R
Enter number of positions 2
Array After Shift 0 0 15 18 19 20 23 28 39 0
====================================================
Bonus: Change the program to do Array rotation rather than shifting.
For Example:
Enter 10 elements of array A:
17 11 12 15 18 19 20 23 28 39
Enter Rotate direct L
Enter number of positions 3
Array After Rotation 15 18 19 20 23 28 39 17 11 12
Enter Rotate direct R
Enter number of positions 2
Array After Rotation 11 12 15 18
Numbers and figures are an essential part of our world, necessary for almost everything we do every day. As important…
APPROVED BY CLIENTS
Finding a professional expert in "partial differential equations" in the advanced level is difficult.
You can find this expert in "Assignmentexpert.com" with confidence.
Exceptional experts! I appreciate your help. God bless you!
Comments
Leave a comment