首页 > 解决方案 > 关于使用数组的双向链表的问题

问题描述

在此处输入图像描述

嗨,我们开始谈论数据结构,我无法为这个问题想出一个代码这基本上是一个双向链表的 3 个数组实现,P(上一个指针)/N(下一个指针)/D(数据)但我无法理解如何在函数之外使用新数组?我的意思是根据我的理解,我们得到了一个数组,我们正在操纵它,但这只是让我困惑新数组是如何发挥作用的。

同样在后续问题中,它们是指复杂性还是我们需要执行的每个操作?顺便说一句,这是我第一次编写psedueocode,看起来还好吗?

InsertFirst(k)

if (Free ≠ -1) then  
  q = free 
else                         //Create new arrays
  newArray ➜ newD(2n)  
  newArray ➜ newP(2n) 
  newArray ➜ newN(2n)

 for i=0 ➜ n   
     newD[i] = D[i]   
     newP[i] = D[i]   
     newN[i] = D[i]

  newD[q] = k                //Insert first if list is full
  Free = newN[Free]  
  newN[q] = L  
  newP[L] = q  
  L = q  
  return

D[q] = k                //Insert first if list is not full
Free = N[Free] 
N[q] = L 
P[L] = q 
L = q 
return

标签: arrayslinked-listdoubly-linked-list

解决方案


推荐阅读