Categories:
.NET (357)
C (330)
C++ (183)
CSS (84)
DBA (2)
General (7)
HTML (4)
Java (574)
JavaScript (106)
JSP (66)
Oracle (114)
Perl (46)
Perl (1)
PHP (1)
PL/SQL (1)
RSS (51)
Software QA (13)
SQL Server (1)
Windows (1)
XHTML (173)
Other Resources:
How do you find out if a linked-list has an end? (i.e. the list is not a cycle)
How do you find out if a linked-list has an end? (i.e. the list is not a cycle)
✍: Guest
You can find out by using 2 pointers. One of them goes 2 nodes each time. The second one goes at 1 nodes each time. If there is a cycle, the one that goes 2 nodes each time will eventually meet the one that goes slower. If that is the case, then you will know the linked-list is a cycle.
2012-01-24, 2440👍, 0💬
Popular Posts:
. How can a servlet refresh automatically if some new data has entered the database? You can use a c...
What invokes a thread's run() method? After a thread is started, via its start() method of the Threa...
Advantages of a macro over a function? Macro gets to see the Compilation environment, so it can expa...
How To Create an Add-to-My-Yahoo Button on Your Website? - RSS FAQs - Adding Your Feeds to RSS News ...
What is the difference between mysql_fetch_object() and mysql_fetch_array() functions in PHP? mysql_...