Program To Print Reverse String by Using Stack
Program To Print Reverse String by Using Stack
#include
#include
typedef struct stack
{
char b[100];
int top;
}stack;
void push(stack *s,char k)
{
if(s->top==99)
printf("\n Stack is full ");
else
s->b[++s->top]=k;
}
char pop(stack *s)
{
char c;
if(s->top==(-1))
printf("\n Stack is empty");
else
else
c=s->b[s->top--];
return c;
}
void main()
{
char name[100];
stack s;
clrscr();
s.top=-1;
printf("\nEnter name :");
gets(name);
int i=0;
while(name[i]!='\0')
{
push(&s,name[i]);
i++;
}
printf("\n Reverse string is :");
while(s.top!=-1)
{
printf("%c",pop(&s));
}
getch(); }
/* Program of reversing a string using stack */
#include
#define MAX 20
#include
push(char item)
{
if(top == (MAX-1))
printf("Stack Overflow\n");
else
stack[++top] =item;
}/*End of push()*/
char pop()
{
if(top == -1)
printf("Stack Underflow\n");
else
return stack[top--];
}/*End of pop()*/
#include
#include
typedef struct stack
{
char b[100];
int top;
}stack;
void push(stack *s,char k)
{
if(s->top==99)
printf("\n Stack is full ");
else
s->b[++s->top]=k;
}
char pop(stack *s)
{
char c;
if(s->top==(-1))
printf("\n Stack is empty");
else
else
c=s->b[s->top--];
return c;
}
void main()
{
char name[100];
stack s;
clrscr();
s.top=-1;
printf("\nEnter name :");
gets(name);
int i=0;
while(name[i]!='\0')
{
push(&s,name[i]);
i++;
}
printf("\n Reverse string is :");
while(s.top!=-1)
{
printf("%c",pop(&s));
}
getch();
}
#include <stdio.h>
#include <conio.h>
#include <string.h>
void main()
{
char str[10],temp;
int i,len;
printf("Enter String : ");
scanf("%s",str);
len=strlen(str)-1;
for(i=0;i<strlen(str)/2;i++)
{
temp=str[i];
str[i]=str[len];
str[len--]=temp;
}
printf("%s",str);
getch();
#include<conio.h>
#include<string.h>
void main()
int i l;
gets(name);
l strlen(name);
for(i 0;i<l;i++)
name[i] rev[l-1-i];
i++;
}
getch();
#include<stdio.h>
#include<string.h>
#include <conio.h>
main()
int i j p;
clrscr();
gets(s);
j i;
r[i] s[p];
getch();
}
#include <stdio.h>