A reader submitted the interview questions he was asked. More C/C++ questions will be added here, as people keep sending us a set of 2-3 questions they got on their job itnerview.
Q1: Tell how to check whether a linked list is circular.
A: Create two pointers, each set to the start of the list. Update each as follows:
while (pointer1) {
pointer1 = pointer1->next;
pointer2 = pointer2->next; if (pointer2) pointer2=pointer2->next;
if (pointer1 == pointer2) {
print ("circularn");
}
}
Q2: OK, why does this work?
If a list is circular, at some point pointer2 will wrap around and be either at the item just before pointer1, or the item before that. Either way, it’s either 1 or 2 jumps until they meet.
How can you quickly find the number of elements stored in a a) static array b) dynamic array ?
Why is it difficult to store linked list in an array?
How can you find the nodes with repetetive data in a linked list?
Write a prog to accept a given string in any order and flash error if any of the character is different. For example : If abc is the input then abc, bca, cba, cab bac are acceptable but aac or bcd are unacceptable.
This is a C question that I had for an intern position at Microsoft: Write out a function that prints out all the permutations of a string. For example, abc would give you abc, acb, bac, bca, cab, cba. You can assume that all the characters will be unique. After I wrote out my function, he asked me to figure out from the code how many times the printf statement is run, and also questions on optimizing my algorithm.
What’s the output of the following program? Why?
#include <stdio.h>
main()
{
typedef union
{
int a;
char b[10];
float c;
}
Union;
Union x,y = {100};
x.a = 50;
strcpy(x.b,"hello");
x.c = 21.50;
printf("Union x : %d %s %f n",x.a,x.b,x.c );
printf("Union y :%d %s%f n",y.a,y.b,y.c);
}
Given inputs X, Y, Z and operations | and & (meaning bitwise OR and AND, respectively)
What is output equal to in
output = (X & Y) | (X & Z) | (Y & Z)
Read all | Browse topics: C++
59 Comments
1. i think this will work for
while(node)
{
If(node==start)
printf(”circular”);
node=node->next;
}
2. Chinmaya,
Your solution works only if loop begins at first element. But original solution works for all cases.
3. this is a very useful site for freshers like me and who are willing to gain more knowledge. i have many other ideas which will help this site to comeup
if u can give a chance i will tell i m frm hyderabad
4. How about those codes:
node = start->next;
while(node)
{
if(node == start)
{
printf(”circular”);
return;
}
node = node->next;
}
5. The posted solution is flawed in that it can (and usually will) seg-fault on non-circular lists. A correct solution should have a “not circular” result as well.
6. how can u find no of elements in an array quickly?
if it is a dynamic array(linked list) the tradition is to keep the count variable in the head
and incrementing it everytime an insertion is performed and decrementing whenever a deletion is performed.so by seeing that count vaiable we can easily tell no. of elements.
7. Write a prog to accept a given string in any order and flash error if any of the character is different. For example : If abc is the input then abc, bca, cba, cab bac are acceptable but aac or bcd are unacceptable.
program
**************************************************
#define true 1
#define false 0
int* isalreadyread; /* this array is used to make sure that
int main(void) the characters in the original,which r matched with a char
{ in the dup is marked as ‘already read’*/
char* original; /* this string holds the original string like..abc*/
char* dup; /* this string is used to hold the duplicates like acb bac cab cba…*/
int isokay(char* ,char* ); /* this is the function(which intern calls many) which checks whether the string is okay*/
int origlength;
int flag;
void initilaizing_isalreadyread();
printf(”\n enter the original string”);
scanf(”%s”,original);
origlength=strlen(original);
isalreadyread=(int*) calloc(origlength,sizeof(int));
flag=true;
while(flag)
{
printf(”enter the duplicate string”);scanf(”%s”,dup);
initializing_isread(origlength);
flag=isokay(original,dup);
if(flag)
printf(”%s”,dup);
}
} /* end of main*/
int isokay(char* original,char* dup)
{
int reflength=strlen(original);
int duplength=strlen(dup);
int found(char c,char* str);
if(reflength!=duplength)
return false; /* this is obvious*/
for(int i=0;i
8. Write out a function that prints out all the permutations of a string.
For example, abc would give you abc, acb, bac, bca, cab, cba.
It can be observed that the number of combinations of string, of length N,
is N!. Consider an example:
string: 123
Length: 3
Combination: 3! = 6
Output: 123 132 321 312 231 213
Following is a program to print all the combination a string:
1 /*
2 * str_combi.c – Print all the combinations of a string
3 * Author – Vijay Kumar R Zanvar
4 * Date – Feb 16, 2004
5 */
6
7 #include
8 #include
9 #include
10
11 void
12 string_combi ( char * s, int len )
13 {
14 int i;
15 char tmp;
16 static int j;
17 static char *p;
18
19 if ( !p )
20 p = s;
21
22 for ( i = 1; i 2 )
25 string_combi ( s+1, len-1 );
26 else
27 {
28 j++;
29 printf ( “%d: %s\t”, j, p );
30 if ( !( j%10 ) )
31 puts ( “” );
32 }
33 if ( i
9. The was some problem during the upload of comment 8 above.
See a program to print combination of strings here:
10. chinmaya,
ur condition within the while loop is never going to be false if it is a circular
linked list. a break is needed.
11. Got a question that extends on the detecting circular linked list question:
Given the constraints that you cannot modify the struct (or class) of the elements, and that you have to remove the loop in the cyclic linked list in O(n) time and O(1) space, how would you do it?
By removing the loop, I mean something like:
_______________________________
__ __ __ _| __ __ __ _|
| | -> | | -> | | -> | | -> | | -> | | -> | | -> | |
— — — — — — — –
Given this linked list, how do you make the last element in the list to point to NULL in O(n) time and O(1) space?
I couldn’t think of a solution that uses O(1) space without modifying the structure. If I was allowed, I could just have a visited flag inside the struct. I’ll then have 2 pointers, a current and a previous. For every node traversed by the current, I will set the flag to true, and each traversal, I will check whether that flag is set to true. If it is, then the previous pointer is the last element of the list, and I can just set the next to NULL. This will also be in O(n) time.
Any insights on this?
12. The picture of the linked list was kinda screwed up…
Anyway, that picture has 8 elements, with the last element pointing to the 4th element, thus making a loop in the list.
13. answer for finding that link list is circular is
int count=0;
while (node)
{
if(node == start && count != 0) {
printf(”Circular”);
exit(0);
}
p = node->next;
q = node->next;
if(node == start)
node->next = null;
14. answer for finding that link list is circular is
int count=0;
while (node)
{
if(node == start && count != 0) {
printf(”Circular”);
exit(0);
}
p = node->next;
q = node->next;
if(node == start)
node->next = null;
else
node->next = r;
p->next = node;
node = q;
r = p;
count = count + 3;
}
15. iscircular(Node* head) /* check whether a link list is circular */
{
/* assume that linklist has a header which keeps a count of no.
of nodes in the list */
Node* temp=head;
while(head->data–)
temp=temp->next;
if(temp->next=head->next)/*1st node actually is next node to head*/
return TRUE;
return FALSE;
}
16. constructor can be static or not?and why? in c++
17. Not to mention the glaring access-violation once pointer2 becomes NULL(though this error indicates ‘not circular’), the unnecessity of traversing pointer1(though doing so does not impact numof iterations), and the lack of terminating conditions(though still technically within the guidlines by only “checking for circular”), the solution is FLAWED in that it will print “Circular” for non-circular lists with 1 node!!! (when Pointer1 and Pointer2 are both NULL) I did think it was a kinda cool idea to weed out the non-circular lists in (num of Nodes)/2 iterations, but the extra traversal code i think outweighs any benefit.
My elegant solution, if i do say so myself:
//assert: list is not empty
for(node=head->next; node!=NULL && node!=head; node=node->next);
if(node==NULL) cout
18. oops, that last statement should read:
if(node==NULL) printf(”Non-circular”);
else printf(”Circular”);
19. dawid,
i dont think my code is lack of terminating condition. i have put while(head->data–)
but i should have copied that head->data into a temporary variable. it should look like
int temp1=head->data
while(temp1–)…………
i dont think it will print “circular” for all single node lists.
if the’next’ of the single node is the address of the node…it will print circular.
otherwise it will print “not circular”.
the idea is to get the address in the ‘next’ field of the last node(node which was inserted latest)
i dont think there is a better way than traversing to reach ‘last’ node.
And…in ur code u assumed that the ‘last’ node’s next point to the Head.
i think its not a good design. it ruins the whole list then.
20. Sorry karthikeyan, I should have been more clear: I was referring to the original solution (by default). It seems to have been torn up enough already, but i wanted to show off my fancy 1 line traversal.
However, in rebuttal:
-You’re fired! Mistaking an equality operator(==) with an assignment(=) is an offense punishable by death.
-Your solution is unintelligible with that mangled loop condition. However relying on a count of num of nodes makes your algorithm possibly unscalable to lists with dummy nodes, for example.
-A chain of pointers will either end in a NULL pointer(if programmed responsibly), or you’ll eventually be back where you started again. I don’t see how this testing ruins a list. Your point is noted, though, about a list with a dummy head that is bypassed around the circle (Like this: -0 ); but that doesn’t look like a circle to me, and I feel that head should point to the first node and any extra information should be stored in a wrapping class (because starting at the front of the list would mean dereferencing twice; silly if traversed many times each game loop, for example). However, to address that issue for those small standalone-pointers-as-lists, you would send the first ‘real’ node ( head->next ) to this function. It is not completely efficient in that there is no specific head to terminate at – you must traverse all the way back around to the given node, but it works for any list. My beautiful(concise) function, if i do say so myself:
bool isCircular(Node* node1)
{
if(node1==NULL) return false;
for(Node* node2=node1->next; node2!=NULL && node2!=node1; node2=node2->next);
return (node2!=NULL);
}
Regards, Dawid.
21. dawid,
ur code looks efficient
22. David, your code does not work in case the loop does not begin with the first element. For example:
A->B->C->D->C
I agree though that the question was “check that a linked list is circular” and not “check that a linked list contains a circle”.
23. int main(int argc, char* argv[])
{
//Write a prog to accept a given string in any order and flash error if any of
//the character is different. For example : If abc is the input then abc,
//bca, cba, cab bac are acceptable but aac or bcd are unacceptable.
//program
char code[100];
char ip[100];
int i,count,flag=0;
puts(”Enter the string:”);
scanf(”%s”,ip);
puts(”Enter the comparision string:”);
scanf(”%s”,code);
for(i=0;i
24. I executed the Program uploaded on site: as mentioned in ANS No: 9
But the string are repeated:
For Example following is the programs Output:
Enter String : 123
1: 123
2: 132
3: 231
4: 213
5: 123 (Repeated with 1:)
6: 132 (Repeated with 2:)
Press any key to continue.
The effort to write the program is apperiable. I am also trying to write a program for it.
SMN
25. #include
#include
#include
#define MLS 5
typedef struct listnode *p_node;
typedef struct listnode node;
typedef struct listnode{
int data;
p_node link;
};
void print_list (p_node ptr);
void add(p_node*,p_node*,p_node);
int delet(p_node*);
p_node creat_node(void);
void main()
{
clrscr();
int opselect=0;
p_node node1,node2,node3,node4,node5;
printf(”============START=============”);
if(opselect!=99)
{
printf(” \n enter aselect node \n”);
printf(” \n 1 to add \n”);
printf(” \n 2 to delet \n”);
printf(” \n 3 to exit \n”);
if(opselect==1){ add(,); }
if(opselect==2){ delete(); }
if(opselect==3){ printf(” good by the exit “);}
}
node1=creat_node();
node2=creat_node();
node3=creat_node();
node4=creat_node();
node5=creat_node();
//********************//
node1->data=10;
node1->link=node2;
node2->data=11;
node2->link=node3;
node3->data=12;
node3->link=node4;
node4->data=13;
node4->link=node5;
node5->data=14;
node5->link=NULL;
//*******************//
}
//function creat node//
p_node creat_node(void)
{
p_node lptr;
lptr=(p_node)malloc(sizeof(node));
return(lptr);
}
//function add node//
void add(p_node*rear,p_node*front,int data_insert)
{
p_node temp;
temp=(p_node)malloc(sizeof(p_node));
if(is_full(temp)){ printf(”\n the memory is full \n”);
exit(1); }
temp->data=data_insert;
if(*lptr){
temp->link=node->link;
node->link=temp;
}
else{
temp->link=NULL;
*lptr=temp;
}
}
//function delet node//
void delet(p_node ,p_node trial,p_node)
{
*node=trial->link;
if(trial)
trial->link=trial->link->link;
else
*lptr=(*lptr)->link;
}
//function print nodes//
void print_link(p_node lptr)
{
printf(” \n the list contains: \n “);
while(lptr)
{
printf(” \n \t %d”,lptr->data);
lptr=lptr->link;
}
}
mohammad
26. For printing out all permutations of a string.
Please tell me all ways I can optimize. Any thoughts on a non-recursive algorithm? My C/C++ isn’t very strong. Raised on Java.
void PrintPermu (char *sBegin, char* sRest)
{
int iLoop;
char cTmp;
char cFLetter[1];
char *sNewBegin;
char *sCur;
int iLen;
static int iCount;
iLen = strlen(sRest);
if (iLen == 2)
{
iCount++;
printf(”%d: %s%s\n”, iCount, sBegin, sRest);
iCount++;
printf(”%d: %s%c%c\n”, iCount, sBegin, sRest[1], sRest[0]);
return;
}
else if (iLen == 1)
{
iCount++;
printf(”%d: %s%s\n”, iCount, sBegin, sRest);
return;
}
else
{
// swap the first character of sRest with each of the remaining chars
// recursively call debug print
sCur = (char*)malloc(iLen);
sNewBegin = (char*)malloc(iLen);
for (iLoop = 0; iLoop
Aditya
27. For printing out all permutations of a string.
Please tell me all ways I can optimize. Any thoughts on a non-recursive algorithm? My C/C++ isn’t very strong. Raised on Java.
void PrintPermu (char *sBegin, char* sRest)
{
int iLoop;
char cTmp;
char cFLetter[1];
char *sNewBegin;
char *sCur;
int iLen;
static int iCount;
iLen = strlen(sRest);
if (iLen == 2)
{
iCount++;
printf(”%d: %s%s\n”, iCount, sBegin, sRest);
iCount++;
printf(”%d: %s%c%c\n”, iCount, sBegin, sRest[1], sRest[0]);
return;
}
else if (iLen == 1)
{
iCount++;
printf(”%d: %s%s\n”, iCount, sBegin, sRest);
return;
}
else
{
// swap the first character of sRest with each of the remaining chars
// recursively call debug print
sCur = (char*)malloc(iLen);
sNewBegin = (char*)malloc(iLen);
for (iLoop = 0; iLoop lessthan iLen; iLoop ++)
{
strcpy(sCur, sRest);
strcpy(sNewBegin, sBegin);
cTmp = sCur[iLoop];
sCur[iLoop] = sCur[0];
sCur[0] = cTmp;
sprintf(cFLetter, “%c”, sCur[0]);
strcat(sNewBegin, cFLetter);
debugprint(sNewBegin, sCur+1);
}
}
}
void main()
{
char s[255];
char sIn[255];
printf(”\nEnter a string:”);
scanf(”%s%*c”,sIn);
memset(s,0,255);
PrintPermu(s, sIn);
}
28. What is the size of the empty class’s object?If it is 1byte why?
please help me.
29. Write out a function that prints out all the permutations of a string.
For example, abc would give you abc, acb, bac, bca, cab, cba
Another solution
#include
#include
#include
#include
using namespace std;
typedef set setchar;
char szPermutation[256];
void permutate(setchar charset, char* szPermute )
{
if (!charset.size())
{
cout > strPermutation;
cout
30. Write a prog to accept a given string in any order and flash error if any of the character is different. For example : If abc is the input then abc, bca, cba, cab bac are acceptable but aac or bcd are unacceptable.
program
**************************************************
Simply have an array of 256 elements. Each element of the array corresponds to one character and stores its count in the original string
**************************************************
#include
int* getCharCounts(char* str)
{
int* result = new int[256];
for(int i=0; i>str1;
cout>str2;
int* c1 = getCharCounts(str1);
int* c2 = getCharCounts(str2);
if(match(c1,c2)) cout
31. Code to print permutations of a string using Recursion
======================================================
int perm_count = 0;
void swap(char *s, int t, int p)
{
char tmp;
tmp = s[t];
s[t] = s[p];
s[p] = tmp;
}
void permute(char *s, int p, int n)
{
int i,j;
if (p > n)
{
printf(”%s\n”, s);
perm_count++;
return;
}
for (i=p; i
32. This website has a bug, doesnt publish the entire code. It
chops it to 256 characters !! Too bad
33. Difference Between C and C++? what is clases, Functions explain with suitable program. And please Explain pointer with program. Finally diffence between Structure and Union. Explain the Advantage and disadvantages with program. Sorry for this Question. Ok bye. god Bless you.
34. in Comment #30, why is the array created for 256 chars?
35. Write a prog to accept a given string in any order and flash error if any of the character is different. For example : If abc is the input then abc, bca, cba, cab bac are acceptable but aac or bcd are unacceptable.
program
For this problem i like to give my soln,
Parse the input string (abc)into equivalent numeric value and sum it. do the same for other inputs( cba,cab..). Those subsequent inputs having the repeated character ocurrence will not be equal to the original value, so it will flash’s error. Welcome more suggestions..
36. IsCirCular(Node *pHead)
{
bool bIsCircular = false;
Node *pNewHead = pHead;
while (pNewHead && !bIsCircular)
{
Node* pTemp = pNewHead->Next;
while(pTemp && !bIsCircular)
{
if (pTemp == pNewHead)
{
bIsCircular = true;
}
else
{
pTemp = pTemp->Next;
}
}
pNewHead = pNewHead->Next;
}
return bIsCircular;
}
37. here is a c code, if u run this code u vl get an outputas
0c&0.0000000, can any one explain the reason?
#include
main(0
{
int a=15;
float b=123.1265
printf(”%d%f”,b,a);
}
38. once more 
I think this one is more simple and nice solution for finding all permutations
void process ( char * s, int len , int nCurPos )
{
static int counter = 1;
if( nCurPos != len-1 )
{
process(s, len, nCurPos + 1);
for( int i = nCurPos+1; i != len; ++i )
{
char tmp = s[nCurPos];
s[nCurPos] = s[i];
s[i] = tmp;
process(s, len, nCurPos + 1);
tmp = s[nCurPos];
s[nCurPos] = s[i];
s[i] = tmp;
}
}
else
{
printf(”%d. %s\n”, counter, s);
++counter;
}
return;
}
*NOTE – in both places I put != instead of “less then”, because I can’t figure out, how to put that sign here
int main()
{
char s[50];
printf ( “\n Enter String : ” );
scanf ( “%s%*c”, s );
process ( s, strlen ( s ) , 0);
return EXIT_SUCCESS;
}
Even if the answer to question 1 had the seg fault fixed like thus
while (pointer1) {
pointer1 = pointer1->next;
if (pointer2) pointer2 = pointer2->next;
if (pointer2) pointer2 = pointer2->next;
if (pointer1 == pointer2) {
print (\”circular\n\”);
}
}
It still would not work. A non circular list would end up setting pointer1 = NULL at the top of the last iteration of the while loop. pointer2 would already have been NULL (just got there faster) thus
pointer1 == pointer2 ===> circular!!! but its not.
39. /*
This is a C question that I had for an intern position at Microsoft:
Write out a function that prints out all the permutations of a string.
For example, abc would give you abc, acb, bac, bca, cab, cba.
You can assume that all the characters will be unique.
After I wrote out my function, he asked me to figure out from the code
how many times the printf statement is run, and also questions on optimizing my algorithm.
I think this may be the fastest way for permutations. Please comment:
(this website cannot display “<(less than)”, so i use (”), (!=) and (>) to replace it.
*/
#include “stdio.h”
#include “string.h”
#include “malloc.h”
int num = 0;
void swap (char * input, int nIndexA, int nIndexB)
{
register char temp = input[nIndexA];
input[nIndexA] = input[nIndexB];
input[nIndexB] = temp;
}
void permutations(char * input, const int nLength, const int nBeginPosition)
{
if ( nLength > nBeginPosition+1 )
{
char * pTemp = (char *)malloc(nLength+1);
if ( pTemp == NULL )
return;
strcpy(pTemp, input);
permutations(pTemp, nLength, nBeginPosition+1);
for ( int i=nBeginPosition+1; i!=nLength; i++ )
{
strcpy(pTemp, input);
swap(pTemp, nBeginPosition, i);
permutations(pTemp, nLength, nBeginPosition+1);
}
free(pTemp);
}
else
{
printf(”%03d:\t%s\n”, ++num, input);
}
}
int main()
{
char szInput[10];
strcpy(szInput, “abcd”);
int nLength = strlen(szInput);
permutations(szInput, nLength, 0);
return 0;
}
40. /* Code to check whether a linked list is circular or not */
pointer1 = a_node;
pointer2 = a_node;
while( pointer2 )
{
pointer2 = pointer2->next;
if( pointer2 == pointer1 )
{
puts( “Circular” );
break;
}
if( !pointer2 )
{
puts( “Not circular” );
break;
}
}
41. The Orignal Solution given for Checking whether circular link list is better one as with this solution we can also check for Circular link list which are of
type 6 not 0. By 0 i mean the link list in which the last element points to head. Where as there as link lists of shape 6 in which the last element may point to some other element than start.
42. What is the purpose of the isCircular linked list question?
I don’t see how you take that question and arrive at the two pointer and moving at different speed answer. Looks like you find two different people, those who have heard the answer and those who have not. Is there something I am not seeing? Is there some way that if you have never heard of this soultion start out with a small example and build up to the end soultion?
Rizzo
Rizzo
43. About: output = (X & Y) | (X & Z) | (Y & Z)
output is true if:
Z is true and Y is true
or
X is true and (any Y or Z is true)
Alex
44. to find a circular list
//head is the starting of the list//
//i assumed like, if it is a circular list it will come back to head
//otherwise it will be end with NULL
node = head;
while(node!=NULL)
{
if (node==head)
{
printf(”Circular”);
Exit(0);
}
node = node->next;
}
printf(”Non circular!”);
Is this work fine or will create any problem? please mail me.
if possible tell me the exact way and little bit explanation.
Thanks,
Amarnath
45. Amarnath,
you will exit on the first iteration itself, since
node==head to start with
harshit
Harshit Kumar
46. Answer for Comment 28
To ensure that the addresses of two different objects will be different. For the same reason, “new” always returns pointers to distinct objects.
sach
47. Comment to comment 44: (X,Y,Z bit operations)
Alex, that is not what they meant. The operations are bitwise, therefore the problem is not logical. The X, Y, and Z are numbers and the ourput is also a number. The output will have set such bits, that are also set in at least two input numbers. I think. For example: it would ouput (0) for [1,2,4], and (2) for [2,3,6].
Arnost
48. HI,
I need an algorithm to insert a node in a circular linklist without traversing it.
Regards,
Subha
Subha
49. /*
* Hi, I’ve written a code to get all the permutations from a char array,
* and It is Okay.
* I would like to communicate with all of you about c ++ and c,
* My email address is linlin98449@tom.com, eater to hear from you
*/
#include
#include
int linenum = 0;
void swap(char* pstr, int pos1, int pos2)
{
register char tmp = * ( pstr + pos1 );
* ( pstr + pos1 ) = * ( pstr + pos2 );
* ( pstr + pos2 ) = tmp;
}
void permutation(char* pstr, int len, int startpos)
{
int i;
if(startpos
Wang Yuan Lin
50. //Answer for is Circular link list
//start and p initially the given pointer
While(p)
if(start==(p=p->next))
printf(”Circular”);
printf(”not a circular”);
#What say
Rohit
51. I tried to solve the question using the approach given by Hari 
“Write a prog to accept a given string in any order and flash error if any of the character is different. For example : If abc is the input then abc, bca, cba, cab bac are acceptable but aac or bcd are unacceptable.
Hari ”
#include
#include
void main()
{
char s[10],dup[10];
int sum_org=0,sum_dup=0;
printf(”\nEnter the string “);
scanf(”%s”,s);
sum_org=parse_sum(s);
printf(”\nEnter the duplicate string :”);
scanf(”%s”,dup);
sum_dup=parse_sum(dup);
if(sum_org==sum_dup)
printf(”\nAllowed duplication”);
else
printf(”\nNot same !!”);
}
int parse_sum(char *s)
{
char temp,*c;
int equi,sum=0;
c=s;
while(*c!=’’)
{
temp=*c;
equi=temp;
sum=sum+equi;
c++;
}
return sum;
}
neetu
52. Code for printing out all permutaions of a string, gurantee to work correctly:
#include
#include
#include
//recursive function to permute a string
void permute(char permulist[], int start, int n)
{
char templist[100];
char tempchar;
int i;
if (start == n-1)
{
for (i=0; i>str;
n = strlen(str);
permute(str,0,n);
return 0;
}
kevin
53. test program for comment 53 (print out permutations)
int main()
{
char str[100];
int n;
cout>str;
n = strlen(str);
permute(str,0,n);
system(”PAUSE”);
return 0;
}
kevin
54. The followint header files should be included in Comment 53 and 54:
iostream.h
stdlib.h
string.h
kevin
55. sorry, this website wipes out the character “
kevin
56. can anyone tell how to find the common node in a circular list without flagging?? in o(n) time
Thej
57. can anyone tell how to find the common node in a circular list without flagging?? in o(n) time
Please elaborate the question. It is not clear. What is a common node in cicular list???
Sachidanand Joshi
58. Hi friends this is the best solution to find Circular Linklist in O(n).
// Best solution
function boolean hasLoop(Node startNode){
Node slowNode = Node fastNode1 = Node fastNode2 = startNode;
while (slowNode && fastNode1 = fastNode2.next() && fastNode2 = fastNode1.next()){
if (slowNode == fastNode1 || slowNode == fastNode2) return true;
slowNode = slowNode.next();
}
return false;
}