Learn basic concept of c , c++ and python programming in regularcodes.com

Spread the post

C program to Reverse given array data

Suppose array contain following elements [34, 21, 5, 52, 32, 12, 42, 12, 323, 33, 12, 344, 23].

Stack Areamainarray [0] 34 [1] 21 [2] 5 [3] 52 [4] 32 [5] 12 [6] 42 [7] 12 [8] 323 [9] 33 [10] 12 [11] 344 [12] 23Before Stack Areamainarray [0] 23 [1] 344 [2] 12 [3] 33 [4] 323 [5] 12 [6] 42 [7] 12 [8] 32 [9] 52 [10] 5 [11] 21 [12] 34After

Algorithm:


Time complexity of this program O(n)

swap_data function are swaping array element.

Example: Accepted Output


C Program to reverse array element. Iterative approach.


Execution process:

Stack Areamainarray [0] 23 [1] 344 [2] 12 [3] 33 [4] 323 [5] 12 [6] 42 [7] 12 [8] 32 [9] 52 [10] 5 [11] 21 [12] 34size (int) =13reversearray_data(pointer)index (int) =4size (int) =13swap_datano1(pointer)no2(pointer)

Note given all execution process.

Try it yourself

Spread the post

Recommended Posts: