필터 지우기
필터 지우기

The previous node in a linked list???

조회 수: 3 (최근 30일)
Joe
Joe 2013년 3월 8일
Are you able to access the previous node in a linked list? Like to traverse to the next node in a linked list it would just be
list.node(x).next
but what about the previous node? I assumed it to be something like this:
list.node(x).prev
But unfortunately that's not right....

채택된 답변

Ryan Livingston
Ryan Livingston 2013년 3월 8일
That would depend on whether your list implementation is singly or doubly linked. In the latter case, nodes have info about the previous and next nodes however for singly they only know about the next node.
What kind of thing is list.node(x)? If it is an MCOS object then you can have a look at its methods and properties with:
methods(list.node(x))
properties(list.node(x))
and see if something is available for you.
  댓글 수: 1
Walter Roberson
Walter Roberson 2013년 3월 8일
If the list is singly linked and you need to find the previous node anyhow, then you need to start at the beginning and keep iterating over the links until you find the node whose "next" field indicates the node you are trying to find the previous of.

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

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by