Current location: Hot Scripts Forums » Programming Languages » PHP » [SOLVED] CLL - Circular Linked List


[SOLVED] CLL - Circular Linked List

Reply
  #1 (permalink)  
Old 06-24-08, 09:38 PM
sushi4664's Avatar
sushi4664 sushi4664 is offline
Aspiring Coder
 
Join Date: Apr 2007
Location: USA
Posts: 411
Thanks: 0
Thanked 0 Times in 0 Posts
[SOLVED] CLL - Circular Linked List

I want to iterate through a list of strings and when it ends I want to start from the beginning. The first thing that comes to mind is circular linked lists. Through after very meticulous research (a quick google search ), I have not found any pre-made circular linked list class. Is there something in PHP 5 that encompasses this?
__________________
- sushi
Visit http://napkinz.com/index.php - web comic that is update weekly

-ps: got through the archive...there are really funny comics in there....
Reply With Quote
  #2 (permalink)  
Old 06-25-08, 05:08 AM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
I am not quite sure what you want but would this work?
PHP Code:

$num count($array);
$i 0;

while (
$i $num)
{
   echo 
$array[$i];

   
$i++;

   if (
$i == ($num 1))
       
$i 0;

Not tested, my php skills are very rusty.
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
Reply With Quote
  #3 (permalink)  
Old 06-25-08, 05:53 AM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,515
Thanks: 20
Thanked 109 Times in 106 Posts
Here's another way ...

PHP Code:

$bDone=false;

$aBuffer=$aArray;
while (!
$bDone)  
  foreach (
$aBuffer as $k => $v)
  {
    
// test for $bDone
    
if ($bDone) break;
  } 
Reply With Quote
  #4 (permalink)  
Old 06-25-08, 10:13 AM
sushi4664's Avatar
sushi4664 sushi4664 is offline
Aspiring Coder
 
Join Date: Apr 2007
Location: USA
Posts: 411
Thanks: 0
Thanked 0 Times in 0 Posts
Well, see the thing is, I don't want to reset the array (like physically go back)...

I am just wondering if there is something like a circular linked list in php?
__________________
- sushi
Visit http://napkinz.com/index.php - web comic that is update weekly

-ps: got through the archive...there are really funny comics in there....
Reply With Quote
  #5 (permalink)  
Old 06-25-08, 01:43 PM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,515
Thanks: 20
Thanked 109 Times in 106 Posts
You can use PHP references as pointers, but I don't think it would be worth the effort.

http://www.php.net/manual/en/language.references.php
Reply With Quote
  #6 (permalink)  
Old 06-25-08, 02:16 PM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
Quote:
Originally Posted by sushi4664 View Post
Well, see the thing is, I don't want to reset the array (like physically go back)...

I am just wondering if there is something like a circular linked list in php?
May I ask why? and what's the difference or drawbacks of resetting array's index if does the job easily?
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
Reply With Quote
  #7 (permalink)  
Old 06-26-08, 08:11 PM
sushi4664's Avatar
sushi4664 sushi4664 is offline
Aspiring Coder
 
Join Date: Apr 2007
Location: USA
Posts: 411
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by NeverMind View Post
May I ask why? and what's the difference or drawbacks of resetting array's index if does the job easily?
Well, I ended up doing that. It wasn't worth the trouble to do it the other way.
__________________
- sushi
Visit http://napkinz.com/index.php - web comic that is update weekly

-ps: got through the archive...there are really funny comics in there....
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
how to write linked list darksystem Everything Java 2 04-19-07 09:04 AM
how is the program of the INFIX to POSTFIX in stack using linked list? venice C/C++ 1 08-09-04 11:59 PM


All times are GMT -5. The time now is 07:48 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.