Thursday, 11 September 2014

String is palindrome or not in C program without string functions using Stack with Example


String is palindrome or not in C program without using string functions. This program is used find the entered stack value will be palindrome or not. This program finds the palindrome strings without using string methods at all. The operations will happen because using of stack mechanism in it. Conditional and looping statements are takes place. If the value is same then, print the palindrome text else entered string is not a palindrome.

Palindrome using stack program:

Q: Write a C program to check whether the given String is palindrome or not with using stack.


#include<stdio.h>
#include<conio.h>
#include"stack.c"
main()
{
    clrscr(); //Function to clear previous output
    //Program variable
    char sr[20];
    int j,f;
    STK s;
    init(&s);
    printf("Enter the string"); //Display function
    scanf("%s",sr); //Getting input function
    for(j=0;sr[j]!='\0';j++) //Looping statement
    {
    if(isFull(&s)) //Conditional statement
    {
        printf("Stack value is overflow");
        exit(1);
    }
    push(&s,sr[j]);
    }
    f=0;
    for(i=0;sr[j]!='\0';j++)
    {
        if(isEmpty(&s))
        {
            printf("Stack value is null");
            exit(1);
        }
        if(sr[j]!=pop(&s))
        f=1;
    }
    if(f=1)
        printf("Enter stack is Not Palindrome");
    else
        printf("Enter stack is Palindrome");
    return(0);
}

No comments:

Post a Comment

Note: only a member of this blog may post a comment.