Jump to content

Is a Nested Link List Possible?


russelltaylor05

Recommended Posts

I am trying to create a nested link list where each node in the linked list also has a link list. ( The application is the structure of a drop down menu )

 

Here is what i got but not sure it is possible and from what I understand you can't have nested classes.

 

class element

{

var $title;

var $linked;

var $target;

var $inner;

 

function element($title,$link,$target)

{

$this->title = $title;

$this->linked = $link;

$this->target = $target;

$this->inner = new linklist();

}

function setTitle($item){$this->title = $item;}

function setLink($item){$this->linked = $item;}

function setTarget($item){$this->target = $item;}

function getTitle(){return $this->title;}

function getLink(){return $this->linked;}

function getTarget(){return $this->target;}

}

 

 

class linklist

{

var $length;

var $TOL= 0;

var $data = array();

 

public function linklist()

{

}

public function add($item)

{

$this->data[$this->TOL] = $item;

$this->TOL++;

}

public function get($index)

{

$temp = $this->data[$index];

return $temp;

}

public function remove($index)

{

for($i=$index;$i<$this->TOL-1;$i++)

{

$this->data[$i] = $this->data[$i+1];

}

$this->TOL = $this->TOL -1;

}

public function set($index,$title,$link,$target)

{

$this->data[$index] = new element($title,$link,$target);

}

public function getLength()

{

return $this->TOL;

}

}

Link to comment
https://forums.phpfreaks.com/topic/111981-is-a-nested-link-list-possible/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.