toseef.koliyariwala
BAN USER
void fib(int x, int N, int prv1, int prv2) {
if (x<=N) {
fib(x+1, N, prv1+prv2, prv1);
printf("%d\t", prv1+prv2);
}
}
int main(void) {
int Nth = 10; // Starting from 0th to Nth
if (Nth > 1) {
fib(2, Nth, 1, 0);
}
if (Nth > 0) {
printf("1\t"); //1st fib number
}
if (Nth > -1) {
printf("0\t"); //0th fib number
}
return 0;
}
Another solution using 3 pointers,
void reverseNodes(Node ** head)
{
Node* cur, nxt, prv;
cur = *head;
while(cur)
{
if ( !(nxt = cur->next) ) break;
cur->next = nxt->next;
nxt->next = cur;
if ( cur == *head )
{
*head = nxt;
}
else
{
prv->next = nxt;
}
prv = cur;
cur=cur->next;
}//end of while
}// end of reverseNodes
RepTaylahMacge, Consultant at Accenture
Assigned to manage the requirements of foreign clients specifically those from the Chinese, Arabic, and French-speaking markets.I am passionate ...
Repmarktrejjo, Data Engineer at Accolite software
I’m Mark.I believe life is too short to be serious all the time, so if you cannot laugh ...
Repjesusitahyer, Data Engineer at ASAPInfosystemsPvtLtd
Hello Everyone, I am Jesusita and I am passionate about writing the stories about powerful mantra to get what you ...
RepLizzieGibson, Cloud Support Associate at Aspire Systems
I'm an engineering student from Huntsville, AL USA. Have more interest in management and stuff related to business. Promptly ...
RepSherriMooney, Network Engineer at Arista Networks
I am not a model but as a photographer, I can't see how one could call it fun. Matter ...
Repannehbell8, Quality Assurance Engineer at Globaltech Research
Build and maintain relationships with convention vendors. Resolve issues throughout meeting event timelines.Plan room layouts and event programs, schedule ...
/* O(n) solution to the problem if generator string is "ab" */
- toseef.koliyariwala May 28, 2018char * findpattern(char *str) {
char *tmp;
if (!str || !(*str)) return NULL;
if (*str == 'b') return str;
tmp = str;
do {
tmp = findpattern(tmp+1);
if (!tmp || !(*tmp)) return NULL;
if (*tmp == 'b') tmp++;
} while(*tmp == 'a');
return tmp;
}
int main(void) {
char *op;
char *string = "abbaab";
op = findpattern(string);
if (!op || *op != 0) {
printf("Invalid string\n");
}
else {
printf("Valid string\n");
}
return 0;
}