sonu
BAN USER
Your Algorithm is absolutely correct.
The running code is:
#include<stdio.h>
#include<string.h>
int RegexMatch(char *S1, char* S2, int n1, int n2)
{
int ptr1 = 0; int ptr2 = 0;
while (ptr1 < n1 && ptr2 < n2)
{
if (S1[ptr1] == S2[ptr2])
{
ptr1++; ptr2++;
if (S2[ptr2] == '?')
ptr2++;
if (S2[ptr2] == '*')
{ ptr2++;
while(S1[ptr1-1] == S1[ptr1] && ptr1 < n1)
ptr1++;
}
}
else if (S2[ptr2+1] == '*')
{
ptr2 = ptr2+2;
}
else if (S2[ptr2+1] == '?')
{
ptr2 = ptr2+2;
}
else
{
return 0;
}
}
if (ptr1 < n1) return 0;
if (ptr2 < n2)
{
while(ptr2 < n2)
{
if (S2[ptr2] == '*' || S2[ptr2] == '?')
ptr2++;
else
{
if (S2[ptr2+1] == '?' || S2[ptr2+1] == '*')
ptr2 = ptr2 + 2;
else
return 0;
}
}
}
return 1;
}
int main()
{
char S1[]="aabcccd",S2[]="a*bc*d?e?";
int flag=RegexMatch(S1,S2,strlen(S1),strlen(S2));
if(!flag)
printf("Match Not Found\n");
else
printf("Match Found\n");
getch();
return 0;
}
Thanks Don!!! :)
Here val1<va2 and
[1].treeNode* LowestCommonAncestor(treeNode *node,int val1,int val2);
[2]int hightCount(treeNode *node,int val);
[3]int findShortestLength(treeNode *node,int val1,int val2);
here we find the lowest common Ancestor and the find the hight of the left child found and then hight of right child found.After that we sum the hights.
treeNode* LowestCommonAncestor(treeNode *node,int val1,int val2)
{
if(!node)
return NULL ;
else if((val1<(node->data))&& (val2>(node->data)))
{
return node;
}
else if((val1>(node->data))&& (val2>(node->data)))
{
return(LowestCommonAncestor(node->right,val1,val2));
}
else if((val1<(node->data))&& (val2<(node->data)))
{
return (LowestCommonAncestor(node->left,val1,val2));
}
}
int hightCount(treeNode *node,int val)
{
int count;
if((!node)||(val==(node->data)))
return 0;
else if(val<(node->data))
{
count=(hightCount(node->left,val))+1;
}
else if(val>(node->data))
{
count=(hightCount(node->right,val))+1;
}
return count;
}
int findShortestLength(treeNode *node,int val1,int val2)
{
int leftLength=0,rightLength=0;
treeNode *LCA=LowestCommonAncestor(node,val1,val2);
leftLength=hightCount(LCA->left,val1)+1;
rightLength=hightCount(LCA->right,val2)+1;
return (leftLength+rightLength);
}
RepRussBDycus, Android test engineer at ABC TECH SUPPORT
I am working as a manager in Lionel Kiddie City company. I really enjoy my job. I like to play ...
Repcamillerharry, Data Engineer at Student
Hi, I am Camille from Easton USA. Currently, I am working as Staff assistant at Northern Star company. A managed ...
Repsushiplarson, Animator at Achieve Internet
Hi, I am a creative Assistant Video Editor with experience in all aspects of video production. Working at a post-production ...
Repsylviarashtons, Accountant at ASAPInfosystemsPvtLtd
I am a journalist. Outside the office, I enjoy additional writing time in a different genre of historical fiction. I ...
Repmelonydmaxwell, maintenence engineer at AMD
Hi, I am working as a health information technician and my work is to collect and maintain a patient's ...
Repbarrietrosado, abc at ABC TECH SUPPORT
Hi, I am Barrie, from Ualapue USA. I believe that every challenge has a solution - and I take great satisfaction ...
Repjanicepdaniels1, Backend Developer at Accenture
I decided to become an entrepreneur and work for myself because I wasn't making the money I wanted to ...
Repmariawharris2, Computer Scientist at Adjetter Media Network Pvt Ltd.
Hi I am an IT Project Management Professional with 2 years' experience,Handled project development and documentation of copier rentals ...
Repleighpjoyce, job tessio at CapitalIQ
Welcome to my world.I am a safety-conscious HVAC Engineer with experience with mechanical engineering Brampton HVAC design for commercial ...
Repbrandysolsen, Area Sales Manager at AMD
I am a Social butterflies who enjoy travel.Have fun doing this job and project an atmosphere that reflects Amazon ...
RepI am Susan From Wasilla USA. and my strong interest in yoga and reading historical books. I have a large ...
yes..HasMap will contain 26 letters key and each key will contain the linklist ,having name and phone number in each node, starting with key character in Alphabetically sorted.
- sonu February 09, 2013