Write a program to reverse a string using Stack. - Data Structure using C

Translate

Thursday, December 10, 2020

Write a program to reverse a string using Stack.

 Write a program to reverse a string using Stack.

Sample Input

hello dinesh

Sample Output

hsenid olleh

code👇👇👇👇👇👇👇👇👇👇👇

#include<stdio.h>

#include<string.h>

char stack[1000];

int top=-1;


void push(char item){

top=top+1;

stack[top]=item;

}

void pop(){

    printf("%c",stack[top]);

    top--;

}

void main(){

    int i,n;

    char c[1000],b[1000];

    fgets(c,1000,stdin);

    n=strlen(c);

    for(i=0;i<n-1;i++)

    push(c[i]);

    for(i=0;i<n-1;i++)

    pop();

}



No comments:

Post a Comment

Introduction to Arrays

  Introduction to Arrays An array is a data structure that allows you to store a collection of elements of the same type. Each element in th...