473,379 Members | 1,245 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

How many algo possible???

finding a loop in a lisked list without modifying it.

1.reverse and check for beginning.
2.take two pointers, keep moving 1st by one and 2nd by two locations,
if they meet loop exists.
3.store addresses in an array.
is their any other possible solution???

Apr 5 '07 #1
4 1413
On 5 Apr, 12:29, nishit.gu...@st.com wrote:
finding a loop in a lisked list without modifying it.

1.reverse and check for beginning.
2.take two pointers, keep moving 1st by one and 2nd by two locations,
if they meet loop exists.
3.store addresses in an array.
Option 2 is nearly there.

"Take two pointers. One at element 1 and the next at element 3. See
if they are equal; if not, move P1 by 1 and P2 by 2. Check and
continue. If P1 or P2 is null, there is no loop. If there is one, it
will definitely be detected. One pointer will eventually catch up
with the other (i.e. have the same value), though it might take
several traversals of the cycle to do it."

Courtesy of Peter van der Linden's excellent _Expert C Programming:
Deep C Secrets_
Apr 5 '07 #2
ni**********@st.com wrote:
finding a loop in a lisked list without modifying it.

1.reverse and check for beginning.
2.take two pointers, keep moving 1st by one and 2nd by two locations,
if they meet loop exists.
3.store addresses in an array.
is their any other possible solution???
Do you have a question about C?

<off-topic>

The answer to the question you asked is "Yes."

</off-topic>

--
Eric Sosman
es*****@acm-dot-org.invalid
Apr 5 '07 #3
On Apr 5, 5:25 am, Eric Sosman <esos...@acm-dot-org.invalidwrote:
nishit.gu...@st.com wrote:
finding a loop in a lisked list without modifying it.
1.reverse and check for beginning.
2.take two pointers, keep moving 1st by one and 2nd by two locations,
if they meet loop exists.
3.store addresses in an array.
is their any other possible solution???

Do you have a question about C?

<off-topic>

The answer to the question you asked is "Yes."

</off-topic>

--
Eric Sosman
esos...@acm-dot-org.invalid
Ya obviously bro...nywazz how does it matter whether c/c++
algo for detecting loop wud be same in both c n c++

Apr 6 '07 #4
ni**********@st.com wrote:
Eric Sosman <esos...@acm-dot-org.invalidwrote:
>nishit.gu...@st.com wrote:
.... snip off-topic query
>>
Do you have a question about C?

<off-topic>
The answer to the question you asked is "Yes."
</off-topic>

Ya obviously bro...nywazz how does it matter whether c/c++
algo for detecting loop wud be same in both c n c++
PLONK for boorishness, use of foolish abbreviations, c++ in a c
newsgroup, and general idiocy. I will not be annoyed further by
your existence.

--
<http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfocus.com/columnists/423>
<http://www.aaxnet.com/editor/edit043.html>

"A man who is right every time is not likely to do very much."
-- Francis Crick, co-discover of DNA
"There is nothing more amazing than stupidity in action."
-- Thomas Matthews

--
Posted via a free Usenet account from http://www.teranews.com

Apr 7 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Christian Meisinger | last post by:
hi. has anyone tryed to check .htpasswd passwords with php? everythink works fine as long as they are encrypted with the default CRYPT mode of apaches htpasswd. crypt($pass, $htpass) ===...
10
by: tgh003 | last post by:
So lets assume I have a list of tasks in db table (table looks like: ID, task, sort) And I want to reorder the task list without updating all the records in the table. I dont want to run a sql...
1
by: MJ | last post by:
Hi I am searching for the algo book "The Algorithm Design Manual" by Steve S. Skiena If any one can tell me where can I get the free soft copy of this book It will be rally useful for me ...
4
by: Sean Kelly | last post by:
The old one, not the .NET version. I don't see it listed, but since it's available under .NET I thought I'd ask. Also, there are some API calls which are supposedly not available under most...
3
by: autocomp | last post by:
Hi, Can someone tell me how to incorporate planner with calrender ... or just a calender algo...will help
3
by: eight02645999 | last post by:
hi i need to do something like this eg given a number (as a string) = "123" there are a few combination i want to find with this string, ie "132","321","231","312" and "213". so there are 6...
1
by: soyspinoza | last post by:
hello out there, does anyone know of a good C/C++ implementation of the hungarian algorithm, (i.e. munkres algo?) thanks,
3
by: empiresolutions | last post by:
I am building a app that creates quizzes. This is how it goes - - Create Quiz - Provide up to 10 different types of Quiz Results - Give up to 50 Questions - Each Question has up to 10 possible...
5
by: '2+ | last post by:
well maybe am over-advertising .. excuse me ... am new to python but my "algo-comping cs.sco with python" thang kinda got lauched after all so decided to move from java to python to do these...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.