#include "stdio.h"
#include "conio.h"
#include "string.h"
char s[100];
char pat[100];
char Stack1[100];
char Stack2[100];
int top=-1;
int MAX=100;
int count=0;
void readString()
{
printf("\nEnter String: ");
scanf("%s",&s);
printf("\nEnter Pattern to Search: ");
scanf("%s",&pat);
}
int push(char ch)
{
if(top==MAX)
{
printf("\nStack Overflow: ");return 0;
}
else
{
top++;
Stack1[top]=ch;
}
return 1;
}
char pop()
{
char ch;
if(top==-1)
{
printf("\n Stack Underflow: "); return '-1';
}
else
{
ch=Stack1[top];
top--;
}
return ch;
}
int compare()
{
int patlen=strlen(pat);
int p=strlen(s)-(patlen-1);
for(int m=0;m
#include "conio.h"
#include "string.h"
char s[100];
char pat[100];
char Stack1[100];
char Stack2[100];
int top=-1;
int MAX=100;
int count=0;
void readString()
{
printf("\nEnter String: ");
scanf("%s",&s);
printf("\nEnter Pattern to Search: ");
scanf("%s",&pat);
}
int push(char ch)
{
if(top==MAX)
{
printf("\nStack Overflow: ");return 0;
}
else
{
top++;
Stack1[top]=ch;
}
return 1;
}
char pop()
{
char ch;
if(top==-1)
{
printf("\n Stack Underflow: "); return '-1';
}
else
{
ch=Stack1[top];
top--;
}
return ch;
}
int compare()
{
int patlen=strlen(pat);
int p=strlen(s)-(patlen-1);
for(int m=0;m
{
for(int j=patlen-1;j>-1;j--)
{
Stack2[j]=pop();
}
Stack2[patlen]='\0';
if (!strcmp(pat,Stack2))
{
count++;
}
for(int i=0;i {
push(Stack2[i]);
}
}
printf("\n %d match Found!!!",count);
return 0;
}
void main()
{ clrscr();
readString();
for(int i=0;s[i]!='\0';i++)
{
push(s[i]);
}
compare();
getch();
}
for(int j=patlen-1;j>-1;j--)
{
Stack2[j]=pop();
}
Stack2[patlen]='\0';
if (!strcmp(pat,Stack2))
{
count++;
}
for(int i=0;i
push(Stack2[i]);
}
}
printf("\n %d match Found!!!",count);
return 0;
}
void main()
{ clrscr();
readString();
for(int i=0;s[i]!='\0';i++)
{
push(s[i]);
}
compare();
getch();
}
No comments:
Post a Comment