Reverse String without using String function – Programming Question

Write a program to reverse string without using string function. You don’t have to use any in-built string library function. This problem can be solved by multiple approaches. Let’s check it.

Method 1.

Reverse String using Stack

In my previous post i have explained what is stack and how to implement stack using array.

Stack implementation using Linked List.

Using the same concept let’s create a stack and push all the characters of a string. Once all the characters are pushed then pop the character and print it. This operation will print the string in reverse order .  Check program to reverse a string using stack.

Implement Stack using Array.

Subscribe Our Tutorials

Get Latest Updates on Facebook

Method 2.

Reverse String by Swapping their Position

In this approach we reverse a  string by swapping their position. For this let’s take two indexes (first and last) .

a) Initialize first index with 0 and last index with arraylength-1 .

b) In next step swap the position of character occur in first and last index. Repeat this process until first index is less than or equal to last index.

Reverse String Program in C

C program code to reverse string without using string function.

Reverse String in PHP

We have seen the c code to reverse a string, now let’s write the same code in PHP.

How to Sort String in PHP .

About WebRewrite

I am technology lover who loves to keep updated with latest technology. My interest field is Web Development.
Tagged , , . Bookmark the permalink.