how to make basic Tree data structure

I need an explanation how node.child node.parent can be implemented as moving to next item in tree?
I want a code that defined in class structure for tree data structure
it will be like this in python
class Node():
def __init__(self, parent=None, position=None, child):
self.parent = parent
self.position = position
self.child = child
parent and child holds another node structure

답변 (1개)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2023년 11월 3일

0 개 추천

If understood correctly your question, the structure variable can be built in the following way, e.g.:
Child1 = magic(3);
Child2 = randi(3,2,3);
Child3 = 'Today';
Home = 'City Street zip #';
Parent1.Child1 = Child1;
Parent1.Child2 = Child2;
Parent2.Child3 = Child3;
Family.Parent1 = Parent1;
Family.Parent2 = Parent2;
Family.Home = Home
Family = struct with fields:
Parent1: [1×1 struct] Parent2: [1×1 struct] Home: 'City Street zip #'
disp(Parent1)
Child1: [3×3 double] Child2: [2×3 double]
disp(Parent2)
Child3: 'Today'

댓글 수: 1

Melih Furkan SEN
Melih Furkan SEN 2023년 11월 6일
Not really. I want to step to next child in tree in a loop

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Scope Variables and Generate Names에 대해 자세히 알아보기

제품

릴리스

R2023a

태그

질문:

2023년 11월 3일

댓글:

2023년 11월 6일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by