473,799 Members | 3,209 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1429
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.invalidwrot e:
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.invalidwrot e:
>nishit.gu...@s t.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.securityfoc us.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
9935
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) === $htpass but how to check MD5? if you use ./htpasswd -m .htpasswd user
10
4266
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 update stmt against every record to update the "sort" field. Any other easy way to do this? there has got to be a simple algo out there.
1
1776
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 Regards MJ
4
2849
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 Windows installations (CryptBinaryToString, for example). I don't suppose this has changed? Basically, I'm trying to replicate the functionality of some .NET crypto stuff in C++ and finding that some of the stuff I need isn't available. Sean
3
1653
by: autocomp | last post by:
Hi, Can someone tell me how to incorporate planner with calrender ... or just a calender algo...will help
3
1457
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 combinations altogether. i remember there's a formula for this, but forgot. Does python have any modules/functions to do this? thanks
1
2915
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
2220
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 Answers. - Each Answer is assigned a Weighted value.... for each type of Quiz Result. - Weighted values are in the range of -6, 0, +6. - Each Quiz will also apply the same Weight range for if a M/F is taking and what of 6 age groups the taker is...
5
1332
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 thangs completly platform independently oh .. am just curious who are the guys over here composing weird music with python as my self-introduction...
0
9541
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10484
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10251
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10228
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10027
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6805
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5463
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5585
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3759
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.