コード例 #1
0
 public function testGetDepths()
 {
     $firstLevel1 = new BinaryTreeNode("first level 1");
     $secondLevel1 = new BinaryTreeNode("second level 1");
     $secondLevel2 = new BinaryTreeNode("second level 2");
     $thirdLevel1 = new BinaryTreeNode("third level 1");
     $thirdLevel2 = new BinaryTreeNode("third level 2");
     $thirdLevel3 = new BinaryTreeNode("third level 3");
     $fourthLevel1 = new BinaryTreeNode("fourth level 1");
     $firstLevel1->setLeft($secondLevel1);
     $firstLevel1->setRight($secondLevel2);
     $secondLevel1->setRight($thirdLevel1);
     $secondLevel2->setLeft($thirdLevel2);
     $secondLevel2->setRight($thirdLevel3);
     $thirdLevel2->setLeft($fourthLevel1);
     $firstLevel = new LinkedList();
     $firstLevel->add($firstLevel1);
     $secondLevel = new LinkedList();
     $secondLevel->add($secondLevel1);
     $secondLevel->add($secondLevel2);
     $thirdLevel = new LinkedList();
     $thirdLevel->add($thirdLevel1);
     $thirdLevel->add($thirdLevel2);
     $thirdLevel->add($thirdLevel3);
     $fourthLevel = new LinkedList();
     $fourthLevel->add($fourthLevel1);
     $expected = [$firstLevel, $secondLevel, $thirdLevel, $fourthLevel];
     $this->assertEquals($expected, DFSDepthLister::getDepths($firstLevel1));
     $this->assertEquals($expected, BFSDepthLister::getDepths($firstLevel1));
 }
コード例 #2
0
 public static function isPalindrome(LinkedList $list)
 {
     if ($list->getSize() < 2) {
         return true;
     }
     $first = $list->removeFirst();
     $last = $list->removeLast();
     if ($first !== $last) {
         return false;
     }
     return self::isPalindrome($list);
 }
コード例 #3
0
 function __construct($title = null, $section_id = null)
 {
     parent::__construct();
     $this->title = $title;
     $this->section_id = $section_id;
     $this->title_weight = 'h2';
 }
コード例 #4
0
ファイル: Path.php プロジェクト: DaniloEpic/slast
 public function addComponent(Component $c)
 {
     if ($this->ultimo) {
         $c->setInput($this->ultimo->getElemento()->getOutput());
     }
     parent::append($c);
 }
コード例 #5
0
 private static function populateDepths(array &$depths, BinaryTreeNode $n, $depth)
 {
     $nodeList = $depth < count($depths) ? $depths[$depth] : null;
     if ($nodeList === null) {
         $nodeList = new LinkedList();
         $depths[$depth] = $nodeList;
     }
     $nodeList->add($n);
     $left = $n->getLeft();
     if ($left !== null) {
         self::populateDepths($depths, $left, $depth + 1);
     }
     $right = $n->getRight();
     if ($right !== null) {
         self::populateDepths($depths, $right, $depth + 1);
     }
 }
コード例 #6
0
 function __construct($title, $action, $id, $submitPage = './', $custom_id = '')
 {
     parent::__construct();
     $this->id = $id;
     $this->title = $title;
     $this->action = $action;
     $this->submitPage = $submitPage;
     $this->custom_id = $custom_id . (strlen($custom_id) > 1 ? '_' : '');
 }
コード例 #7
0
 function __construct($title, $page_action, $action = '#')
 {
     parent::__construct();
     $this->title = $title;
     $this->page_action = $page_action;
     $this->action = $action;
     $this->row = array();
     $this->seek_index = 0;
 }
コード例 #8
0
 public static function getDepths(BinaryTreeNode $n)
 {
     $depths = [];
     $nodes = new LinkedList();
     $nodes->add($n);
     while ($nodes !== null) {
         $childNodes = new LinkedList();
         foreach ($nodes as $node) {
             $left = $node->getLeft();
             if ($left !== null) {
                 $childNodes->add($left);
             }
             $right = $node->getRight();
             if ($right !== null) {
                 $childNodes->add($right);
             }
         }
         $depths[] = $nodes;
         $nodes = !$childNodes->isEmpty() ? $childNodes : null;
     }
     return $depths;
 }
コード例 #9
0
 public function testIsNotPalindrome()
 {
     $list = new LinkedList();
     $list->add("A");
     $list->add("B");
     $list->add("C");
     $list->add("D");
     $this->assertFalse(LinkedListPalindromeChecker::isPalindrome($list));
 }
コード例 #10
0
ファイル: LinkedList.php プロジェクト: EdenChan/Instances
 /**
  * Main program.
  *
  * @param array $args Command-line arguments.
  * @return integer Zero on success; non-zero on failure.
  */
 public static function main($args)
 {
     printf("LinkedList main program.\n");
     $status = 0;
     $l1 = new LinkedList();
     $l1->append(57);
     $l1->append('hello');
     $l1->append(NULL);
     printf("%s\n", str($l1));
     printf("isEmpty returns %s\n", str($l1->isEmpty()));
     printf("Using reduce\n");
     $l1->reduce(create_function('$sum, $item', 'printf("%s\\n", str($item));'), '');
     printf("Purging\n");
     $l1->purge();
     printf("%s\n", str($l1));
     return $status;
 }
コード例 #11
0
ファイル: TestLinkedList.php プロジェクト: phlare/utils
 public static function testList()
 {
     $linkedList = new LinkedList();
     if ($linkedList->getCount() !== 0) {
         self::printError("problem creating a new list - count not 0");
     }
     // test insertFront
     $linkedList->insertFront('insertFront');
     if ($linkedList->getCount() !== 1) {
         self::printError("problem adding first element to front - count not 1");
     }
     // ad a second item to the front
     $linkedList->insertFront('insertFrontAgain');
     if ($linkedList->getCount() !== 2) {
         self::printError("problem adding second element to front - count not 2");
     }
     // test getAt
     if ($linkedList->getAt(0) !== 'insertFrontAgain') {
         self::printError("problem with getAt: not finding first node");
     }
     // test getAt
     if ($linkedList->getAt(12) !== null) {
         self::printError("problem with getAt: accessing nonexisting node should have returned null");
     }
     // test insertEnd
     $linkedList->insertEnd('insertEnd');
     if ($linkedList->getAt(2) !== 'insertEnd' || $linkedList->getCount() !== 3) {
         self::printError("problem with insertEnd: inserted item not found");
     }
     // test insertAt
     $linkedList->insertAt('insertedAt2', 2);
     if ($linkedList->getAt(2) !== 'insertedAt2' || $linkedList->getAt(3) !== 'insertEnd') {
         self::printError("problem with insertAt: inserted value not found at proper key");
     }
     $linkedList->insertAt('insertedAt3', 3);
     if ($linkedList->getAt(3) !== 'insertedAt3') {
         self::printError("problem with insertAt: inserted value not found at proper key");
     }
     // test deleteAt
     $linkedList->deleteAt(3);
     if ($linkedList->getAt(3) === 'insertedAt3') {
         self::printError("problem with deleteAt: deleted node still present");
     }
     // test deleting by value
     $linkedList->delete('insertedAt2');
     // test reverse
     $linkedList->reverse('recursive');
     if ($linkedList->getAt(0) !== 'insertEnd') {
         self::printError("problem with reverse");
     }
     $linkedList->reverse();
     // display... for now
     // $linkedList->debug();
     $linkedList->printList('reverse');
     // test empty
     $linkedList->emptyList();
     if ($linkedList->getCount() !== 0) {
         self::printError("problem with emptyList: list count not zero");
     }
 }
コード例 #12
0
ファイル: list.php プロジェクト: xqy/php
    public function getData()
    {
        if ($this->_head != null) {
            $node = $this->pop();
            while ($node) {
                var_dump($node->value . "\n");
                $node = $this->pop();
            }
        } else {
            return "list is empty!\n";
        }
    }
}
class Node
{
    public $value = null;
    public $next = null;
    public $pre = null;
}
$data = array(100, 4, 5, 6, 4, 7, 89, 5, "100c");
$list = new LinkedList();
foreach ($data as $key => $value) {
    $node = new Node();
    $node->value = $value;
    $list->push($node);
    $arr[$key] = $node;
}
var_dump($arr);
//$list->del($arr[2]);
//var_dump($list);
//$list->getData();
 public function add($e)
 {
     assert($this->size() < $this->getExpectedSize());
     return parent::add($e);
 }
コード例 #14
0
/**
 * Gets a sorted array of signature indexes from the supplied nodes.
 *
 * @param array $node_indexs
 *   The array of node indexes to get signatures from.
 * @param array $headers
 *   Header information from the data file.
 *
 * @return array
 *   A sorted array of signature indexes.
 */
function fiftyone_degrees_get_closest_signature_indexs($node_indexs, &$timings, &$debug_info, $headers)
{
    $node_count = count($node_indexs);
    if ($node_count == 1) {
        // There is only 1 list so return that single list.
        $node = fiftyone_degrees_read_node($node_indexs[0], $headers);
        fiftyone_degrees_fill_node_ranked_signatures($node, $headers['info']['max_signatures']);
        $sig_offsets = array();
        foreach ($node['node_ranked_signatures'] as $offset) {
            $sig_offsets[] = $offset;
        }
        return $sig_offsets;
    } else {
        $timings['closest_match_node_sort_time'] = microtime(TRUE);
        $sorted_nodes = array();
        $nodes = array();
        $max_count = 1;
        $iteration = 2;
        for ($i = 0; $i < $node_count; $i++) {
            $node = fiftyone_degrees_read_node($node_indexs[$i], $headers);
            $sorted_nodes[$i] = $node['node_ranked_signature_count'];
            $nodes[] = $node;
        }
        // Sort nodes in ascending order by signature count.
        array_multisort($sorted_nodes, SORT_ASC, $nodes);
        $timings['closest_match_node_sort_time'] = microtime(TRUE) - $timings['closest_match_node_sort_time'];
        $timings['closest_match_node_fill_signatures_time'] = microtime(TRUE);
        for ($i = 0; $i < $node_count; $i++) {
            fiftyone_degrees_fill_node_ranked_signatures($nodes[$i]);
        }
        $timings['closest_match_node_fill_signatures_time'] = microtime(TRUE) - $timings['closest_match_node_fill_signatures_time'];
        $timings['closest_match_filling_linked_list_time'] = microtime(TRUE);
        // Building initial list.
        $linked_list = new LinkedList();
        if (count($nodes) > 0) {
            $node_0_signatures_count = count($nodes[0]['node_ranked_signatures']);
            if ($node_0_signatures_count > $headers['info']['max_signatures']) {
                //  $node_0_signatures_count = $headers['info']['max_signatures'];
            }
            for ($i = 0; $i < $node_0_signatures_count; $i++) {
                $linked_list->addLast(array($nodes[0]['node_ranked_signatures'][$i], 1));
            }
        }
        // Count the number of times each signature index occurs.
        for ($i = 1; $i < $node_count; $i++) {
            $max_count = fiftyone_degrees_get_closest_signatures_for_node($node_count, $nodes[$i]['node_ranked_signatures'], $linked_list, $max_count, $iteration, $headers);
            $iteration++;
        }
        $timings['closest_match_filling_linked_list_time'] = microtime(TRUE) - $timings['closest_match_filling_linked_list_time'];
        $timings['closest_match_sorting_signature_ranks'] = microtime(TRUE);
        $sig_offsets = array();
        $linked_list->current = $linked_list->first;
        while ($linked_list->current !== -1) {
            if ($linked_list->current->value[1] == $max_count) {
                $debug_info['signatures_read']++;
                $sig_offsets[] = $linked_list->current->value[0];
            }
            $linked_list->moveNext();
        }
        $timings['closest_match_sorting_signature_ranks'] = microtime(TRUE) - $timings['closest_match_sorting_signature_ranks'];
        return $sig_offsets;
    }
}
コード例 #15
0
ファイル: wiki_entries.php プロジェクト: rolwi/koala
require_once PATH_LIB . "comments_handling.inc.php";
require_once PATH_LIB . "wiki_handling.inc.php";
$wiki_html_handler = new lms_wiki($wiki_container);
$wiki_html_handler->set_admin_menu("index", $wiki_container);
$grp = $wiki_container->get_environment()->get_creator();
if ($grp->get_name() == "learners" && $grp->get_attribute(OBJ_TYPE) == "course_learners") {
    $grp = $grp->get_parent_group();
}
$content = new HTML_TEMPLATE_IT();
$content->loadTemplateFile(PATH_TEMPLATES . "wiki_entries.template.html");
$cache = get_cache_function($wiki_container->get_id(), 600);
$wiki_entries = $cache->call("lms_wiki::get_items", $wiki_container->get_id());
$recently_changed = new LinkedList(5);
$most_discussed = new LinkedList(5);
$latest_comments = new LinkedList(5);
$no_wiki_entries = count($wiki_entries);
if ($no_wiki_entries > 0) {
    $first_char = "";
    for ($i = 0; $i < $no_wiki_entries; $i++) {
        $this_char = substr(strtoupper($wiki_entries[$i]["OBJ_NAME"]), 0, 1);
        if ($this_char > $first_char) {
            $first_char = $this_char;
            if ($i > 1) {
                $content->parse("BLOCK_CHARACTER");
            }
            $content->setCurrentBlock("BLOCK_CHARACTER");
            $content->setVariable("FIRST_CHAR", h($this_char));
        }
        $char_articles = array();
        while ($i < $no_wiki_entries && $this_char == substr(strtoupper($wiki_entries[$i]["OBJ_NAME"]), 0, 1)) {
コード例 #16
0
ファイル: Queue.php プロジェクト: redtrine/redtrine
 /**
  * @param string $name
  * @param bool $isFifo
  */
 public function __construct($name, $isFifo = true)
 {
     $this->fifo = $isFifo;
     parent::__construct($name);
 }
コード例 #17
0
ファイル: CappedList.php プロジェクト: redtrine/redtrine
 public function __construct($name, $length)
 {
     parent::__construct($name);
     $this->length = $length;
 }
コード例 #18
0
ファイル: Index.class.php プロジェクト: rolwi/koala
 public function execute(\FrameResponseObject $frameResponseObject)
 {
     //CODE FOR ALL COMMANDS OF THIS PAKAGE END
     $user = \lms_steam::get_current_user();
     // Disable caching
     // TODO: Work on cache handling. An enabled cache leads to bugs
     // if used with the wiki.
     \CacheSettings::disable_caching();
     if (!($wiki_container = \steam_factory::get_object($GLOBALS["STEAM"]->get_id(), $this->id))) {
         include "bad_link.php";
         exit;
     }
     if (!$wiki_container instanceof \steam_container) {
         $wiki_doc = $wiki_container;
         $wiki_container = $wiki_doc->get_environment();
         if ($wiki_doc->get_attribute(DOC_MIME_TYPE) != "text/wiki") {
             include "bad_link.php";
             exit;
         }
     }
     //CODE FOR ALL COMMANDS OF THIS PAKAGE END
     defined("OBJ_ID") or define("OBJ_ID", $wiki_container->get_id());
     $wiki_html_handler = new \lms_wiki($wiki_container);
     $wiki_html_handler->set_admin_menu("index", $wiki_container);
     $grp = $wiki_container->get_environment()->get_creator();
     if ($grp->get_name() == "learners" && $grp->get_attribute(OBJ_TYPE) == "course_learners") {
         $grp = $grp->get_parent_group();
     }
     $content = \Wiki::getInstance()->loadTemplate("wiki_entries.template.html");
     //$content = new HTML_TEMPLATE_IT();
     //$content->loadTemplateFile( PATH_TEMPLATES . "wiki_entries.template.html" );
     $cache = get_cache_function($wiki_container->get_id(), 600);
     $wiki_entries = $cache->call("lms_wiki::get_items", $wiki_container->get_id());
     $recently_changed = new \LinkedList(5);
     $most_discussed = new \LinkedList(5);
     $latest_comments = new \LinkedList(5);
     $no_wiki_entries = count($wiki_entries);
     if ($no_wiki_entries > 0) {
         $first_char = "";
         for ($i = 0; $i < $no_wiki_entries; $i++) {
             $this_char = substr(strtoupper($wiki_entries[$i]["OBJ_NAME"]), 0, 1);
             if ($this_char > $first_char) {
                 $first_char = $this_char;
                 if ($i > 1) {
                     $content->parse("BLOCK_CHARACTER");
                 }
                 $content->setCurrentBlock("BLOCK_CHARACTER");
                 $content->setVariable("FIRST_CHAR", h($this_char));
             }
             $char_articles = array();
             while ($i < $no_wiki_entries && $this_char == substr(strtoupper($wiki_entries[$i]["OBJ_NAME"]), 0, 1)) {
                 $char_articles[] = $wiki_entries[$i];
                 if ($recently_changed->can_be_added($wiki_entries[$i]["DOC_LAST_MODIFIED"])) {
                     $recently_changed->add_element($wiki_entries[$i]["DOC_LAST_MODIFIED"], $wiki_entries[$i]);
                 }
                 if (isset($wiki_entries[$i]["COMMENTS_NO"]) && $most_discussed->can_be_added($wiki_entries[$i]["COMMENTS_NO"]) && $wiki_entries[$i]["COMMENTS_NO"] > 1) {
                     $most_discussed->add_element($wiki_entries[$i]["COMMENTS_NO"], $wiki_entries[$i]);
                 }
                 if (isset($wiki_entries[$i]["COMMENTS_LAST"]) && $latest_comments->can_be_added($wiki_entries[$i]["COMMENTS_LAST"]) && $wiki_entries[$i]["COMMENTS_LAST"] > 0) {
                     $latest_comments->add_element($wiki_entries[$i]["COMMENTS_LAST"], $wiki_entries[$i]);
                 }
                 $i++;
             }
             $i--;
             $no_articles_in_first_row = ceil(count($char_articles) / 2);
             $content->setCurrentBlock("BLOCK_COLUMN");
             for ($c = 0; $c < $no_articles_in_first_row; $c++) {
                 $content->setCurrentBlock("BLOCK_ARTICLE");
                 $content->setVariable("ARTICLE_LINK", PATH_URL . "wiki/viewentry/" . $char_articles[$c]["OBJ_ID"] . "/");
                 $content->setVariable("ARTICLE_NAME", str_replace(".wiki", "", h($char_articles[$c]["OBJ_NAME"])));
                 $content->parse("BLOCK_ARTICLE");
             }
             $content->parse("BLOCK_COLUMN");
             $content->setCurrentBlock("BLOCK_COLUMN");
             for ($c = $no_articles_in_first_row; $c < count($char_articles); $c++) {
                 $content->setCurrentBlock("BLOCK_ARTICLE");
                 $content->setVariable("ARTICLE_LINK", PATH_URL . "wiki/viewentry/" . $char_articles[$c]["OBJ_ID"] . "/");
                 $content->setVariable("ARTICLE_NAME", str_replace(".wiki", "", h($char_articles[$c]["OBJ_NAME"])));
                 $content->parse("BLOCK_ARTICLE");
             }
             $content->parse("BLOCK_COLUMN");
             $content->parse("BLOCK_CHARACTER");
         }
         foreach ($wiki_entries as $entry) {
             $content->setCurrentBlock("BLOCK_ARTICLE");
             $content->setVariable("VALUE_WIKI_ENTRY", h($entry["OBJ_NAME"]));
             $content->setVariable("LINK_WIKI_ENTRY", PATH_URL . "wiki/viewentry/" . $wiki_container->get_id() . "/" . h($entry["OBJ_NAME"]));
             $content->setVariable("LABEL_LAST_MODIFICATION", gettext("last edited"));
             $content->setVariable("VALUE_POSTED_BY", $entry["DOC_USER_MODIFIED"]);
             $content->setVariable("POST_PERMALINK", PATH_URL . "wiki/viewentry/" . $entry["OBJ_ID"] . "/");
             $content->setVariable("VALUE_DATE_TIME", strftime("%x %X", $entry["OBJ_CREATION_TIME"]));
             $content->setVariable("POST_PERMALINK_LABEL", gettext("permalink"));
             $content->parse("BLOCK_ARTICLE");
         }
     }
     /* TODO: check if these functions can be deleted
     		 $wiki_html_handler->set_widget_latest_comments( $latest_comments );
     		 $wiki_html_handler->set_widget_last_changed( $recently_changed );
     		 $wiki_html_handler->set_widget_most_discussed( $most_discussed );
     		 $wiki_html_handler->set_widget_access( $grp );
     		 */
     //TODO: SET RSS_FEEDS
     WIKI_RSS ? $portal->set_rss_feed(PATH_URL . "services/feeds/wiki_public.php?id=" . OBJ_ID, gettext("Feed"), gettext("Subscribe to this forum's Newsfeed")) : "";
     $wiki_html_handler->set_main_html($content->get());
     $rootlink = \lms_steam::get_link_to_root($wiki_container);
     WIKI_FULL_HEADLINE ? $headline = array($rootlink[0], $rootlink[1], array("link" => $rootlink[1]["link"] . "communication/", "name" => gettext("Communication")), array("link" => "", "name" => h($wiki_container->get_name()))) : ($headline = array(array("link" => "", "name" => h($wiki_container->get_name()))));
     $frameResponseObject->setHeadline($headline);
     $widget = new \Widgets\RawHtml();
     $widget->setHtml($wiki_html_handler->get_html());
     $frameResponseObject->addWidget($widget);
     return $frameResponseObject;
 }
コード例 #19
0
ファイル: main.php プロジェクト: pandaoknight/samplecode
        $this->next = $next;
    }
    public function travel()
    {
        print "travel start:\n";
        $traveled = array();
        $curr = $this;
        while (true) {
            print $curr->val;
            // 检查环
            if (in_array($curr, $traveled)) {
                print " circled-link-list-node";
                break;
            }
            $traveled[] = $curr;
            if (empty($curr->next)) {
                break;
            }
            print " => ";
            $curr = $curr->next;
        }
        print "\ntravel end.\n";
    }
}
$list = new LinkedList(1, null);
$list->travel();
$list = new LinkedList(1, new LinkedList(2, null));
$list->travel();
$list = new LinkedList(1, new LinkedList(2, null));
$list->next->next = $list;
$list->travel();
コード例 #20
0
ファイル: InetAddress.php プロジェクト: robo47/BlazeFramework
 /**
  * Add an entry to the cache. If there's already an
  * entry then for this host then the entry will be
  * replaced.
  */
 public function put(\blaze\lang\String $host, \blaze\lang\Object $address)
 {
     $policy = $this->getPolicy();
     if ($policy == InetAddressCachePolicy::NEVER) {
         return $this;
     }
     // purge any expired entries
     if ($policy != InetAddressCachePolicy::FOREVER) {
         // As we iterate in insertion order we can
         // terminate when a non-expired entry is found.
         $expired = new LinkedList();
         $i = $cache->keySet()->iterator();
         $now = System::currentTimeMillis();
         while ($i->hasNext()) {
             $key = $i->next();
             $entry = $cache->get($key);
             if ($entry->expiration >= 0 && $entry->expiration < $now) {
                 $expired->add($key);
             } else {
                 break;
             }
         }
         $i = $expired->iterator();
         while ($i->hasNext()) {
             $cache->remove($i->next());
         }
     }
     // create new entry and add it to the cache
     // -- as a HashMap replaces existing entries we
     //    don't need to explicitly check if there is
     //    already an entry for this host.
     $expiration;
     if ($policy == InetAddressCachePolicy::FOREVER) {
         $expiration = -1;
     } else {
         $expiration = System::currentTimeMillis() + $policy * 1000;
     }
     $entry = new CacheEntry($address, $expiration);
     $cache->put($host, $entry);
     return $this;
 }
コード例 #21
0
 public function testLinkedList()
 {
     $list = new LinkedList();
     $this->assertEquals(0, $list->getSize());
     $this->assertTrue($list->isEmpty());
     $this->assertNull($list->peekFirst());
     $this->assertNull($list->peekLast());
     $this->assertNull($list->removeFirst());
     $this->assertNull($list->removeLast());
     $count = 0;
     foreach ($list as $key => $value) {
         $count++;
     }
     $this->assertEquals(0, $count);
     $list->add("one");
     $this->assertEquals(1, $list->getSize());
     $this->assertFalse($list->isEmpty());
     $list->add("two");
     $this->assertEquals(2, $list->getSize());
     $this->assertFalse($list->isEmpty());
     $list->add("three");
     $this->assertEquals(3, $list->getSize());
     $this->assertFalse($list->isEmpty());
     $expected = ["one", "two", "three"];
     $i = 0;
     foreach ($list as $key => $value) {
         $this->assertEquals($i, $key);
         $this->assertEquals($expected[$i], $value);
         $i++;
     }
     $this->assertEquals(3, $i);
     $this->assertEquals("one", $list->peekFirst());
     $this->assertEquals("one", $list->removeFirst());
     $this->assertEquals(2, $list->getSize());
     $this->assertEquals("three", $list->peekLast());
     $this->assertEquals("three", $list->removeLast());
     $this->assertEquals(1, $list->getSize());
     $this->assertEquals("two", $list->peekFirst());
     $this->assertEquals("two", $list->removeFirst());
     $this->assertEquals(0, $list->getSize());
     $this->assertTrue($list->isEmpty());
     $list->add("four");
     $this->assertEquals(1, $list->getSize());
     $this->assertFalse($list->isEmpty());
     foreach ($list as $key => $value) {
         $this->assertEquals(0, $key);
         $this->assertEquals("four", $value);
     }
     $this->assertEquals("four", $list->peekFirst());
     $this->assertEquals("four", $list->removeLast());
     $this->assertEquals(0, $list->getSize());
     $this->assertTrue($list->isEmpty());
 }
            if ($node === $val) {
                return $node;
            }
        }
        return $node;
    }
    public function getPrev()
    {
        return $this->key() - 1 >= 0 ? $this[$this->key() - 1] : 'NULL';
    }
    public function getNext()
    {
        return $this[$this->key() + 1] !== NULL ? $this[$this->key() + 1] : 'NULL';
    }
}
$LL = new LinkedList();
$LL->insert("Akeda");
$LL->insert("Dwi");
$LL->insert("Stevey");
$LL->insert("Paul");
// Function to test given keyword.
function test_searching($keyword = '')
{
    global $LL;
    if ($LL->search($keyword) !== NULL) {
        echo "Node with value '{$keyword}' is found\n";
        echo "The previous node of '{$keyword}' is : " . $LL->getPrev() . "\n";
        echo "The next node of '{$keyword}' is : " . $LL->getNext() . "\n";
    } else {
        echo "Node with value '{$keyword}' is NOT found\n";
    }
コード例 #23
0
 /**
  * @dataProvider providerReverse
  * @param array $originalValues
  * @param array $expectedValues
  */
 public function testReverseRecursive(array $originalValues, array $expectedValues)
 {
     $list = new LinkedList($originalValues);
     $this->assertEquals($originalValues, $list->toArray());
     $list->reverseRecursive();
     $this->assertEquals($expectedValues, $list->toArray());
 }
コード例 #24
0
ファイル: LinkedList.php プロジェクト: tiscomsci29/PHP_Class
        $this->tail->next = $node;
        $this->tail = $this->tail->next;
        $this->size++;
    }
    public function get($pos)
    {
        return $this->go($pos)->next->data;
    }
    private function go($pos)
    {
        $node = $this->head;
        for ($i = 0; $i < $pos; $i++) {
            $node = $node->next;
        }
        return $node;
    }
    public function size()
    {
        return $this->size;
    }
}
$linkedlis = new LinkedList();
$linkedlis->add('2');
$linkedlis->add('4');
$linkedlis->add('6');
$linkedlis->add('8');
echo $linkedlis->size();
echo $linkedlis->get(0);
echo $linkedlis->get(1);
echo $linkedlis->get(2);
echo $linkedlis->get(3);
コード例 #25
0
ファイル: wiki_entries.php プロジェクト: rolwi/koala
<?php

require_once PATH_LIB . "comments_handling.inc.php";
require_once PATH_LIB . "wiki_handling.inc.php";
$wiki_html_handler = new lms_wiki($wiki_container);
$wiki_html_handler->set_admin_menu("index", $wiki_container);
$grp = $wiki_container->get_environment()->get_creator();
if ($grp->get_name() == "learners" && $grp->get_attribute(OBJ_TYPE) == "course_learners") {
    $grp = $grp->get_parent_group();
}
$content = new HTML_TEMPLATE_IT();
$content->loadTemplateFile(PATH_TEMPLATES . "wiki_entries.template.html");
$cache = get_cache_function($wiki_container->get_id(), 600);
$wiki_entries = $cache->call("lms_wiki::get_items", $wiki_container->get_id());
$recently_changed = new LinkedList(5);
$most_discussed = new LinkedList(5);
$latest_comments = new LinkedList(5);
$no_wiki_entries = count($wiki_entries);
if ($no_wiki_entries > 0) {
    $first_char = "";
    for ($i = 0; $i < $no_wiki_entries; $i++) {
        $this_char = substr(strtoupper($wiki_entries[$i]["OBJ_NAME"]), 0, 1);
        if ($this_char > $first_char) {
            $first_char = $this_char;
            if ($i > 1) {
                $content->parse("BLOCK_CHARACTER");
            }
            $content->setCurrentBlock("BLOCK_CHARACTER");
            $content->setVariable("FIRST_CHAR", h($this_char));
        }
        $char_articles = array();