C General - Deteting Circular Linked List
Interview Question Database For Software Developers
|
|
| Deteting Circular Linked List | | Can you tell me how to check whether a linked list is
circular? | | By: Guest | Create two pointers, and set both 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");
}
}
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.
| | ID: 12 | Rank: 1585 | Votes: 0 | Views: 483 | Submitted: 20070226 |
1491 :-) | | "union" Data Type | | What's the output of the following program? And
why?
#include
main() {
typedef union {
int a;
char b[10];
float c;
}
Union;
Union x... | | Submitted: 20070226 |
|
1511 :-) | | Printing Permutaions of a String | | 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.... | | Submitted: 20070226 |
|
Copyright © 2009 FYIcenter.com
All rights in the contents of this Website are reserved by the individual author.
No part of the contents may be reproduced in any form without author's permission.
|
|
|