Data structures 如何通过以下操作手动跟踪链表X?

Data structures 如何通过以下操作手动跟踪链表X?,data-structures,linked-list,stack,Data Structures,Linked List,Stack,我正试图回答下面这个问题,我被卡住了 通过以下操作手动跟踪链表X: X.add("Fast"); X.add("Boy"); X.add("Doctor"); X.add("Event"); X.add("City"); X.addLast("Zoo"); X.addFirst("Apple"); X.add (1, "Array"); X.remove("Fast"); X.remove (2); X.removeFirst (); X.removeLast (); 这就是我手

我正试图回答下面这个问题,我被卡住了

通过以下操作手动跟踪链表X:

X.add("Fast"); 
X.add("Boy"); 
X.add("Doctor"); 
X.add("Event"); 
X.add("City"); 
X.addLast("Zoo"); 
X.addFirst("Apple"); 
X.add (1, "Array");
X.remove("Fast");
X.remove (2);
X.removeFirst ();
X.removeLast ();
这就是我手工追踪的方式,我试图了解我是否/哪里做错了,因为我在别处看到了令人困惑的答案:

快速

男孩快速

医生男孩快速

事件 医生男孩快速

城市 事件 医生男孩快速

动物园 城市 事件 医生男孩快速

动物园 城市 事件 医生男孩快速的苹果

动物园 城市 事件 医生男孩快速的排列苹果

动物园 城市 事件 医生男孩排列苹果

动物园 城市 事件 医生排列苹果

动物园 城市 事件 医生排列


城市 事件 医生阵列

执行此操作后,您将获得以下列表:

你的LinkedList从头部开始。现在,对于第一个,您必须从头部插入,否则将插入最后一个

快速

男孩->快

医生->男孩->快速

事件->医生->男孩->快速

城市->活动->医生->男孩->快速

城市->活动->医生->男孩->快速->动物园->错误动物园->城市->活动->医生->男孩->快速

苹果->城市->活动->医生->男孩->快速->动物园->错误的动物园->城市->活动->医生->男孩->快速->苹果

Apple->Array->City->Event->Doctor->Boy->Fast->Zoo//错误,因为链接列表应该从Apple开始,但它不是完全正确的,因为LinkedList中没有索引,它应该在您的身上


同样,您也可以执行其他操作。

谢谢。你能解释一下吗?我以为是城市-->事件-->医生-->数组。我在这里做错了什么?你可以检查更新的答案,如果你理解解释,请将其标记为正确。
X.add("Fast"); 
X.add("Boy"); 
X.add("Doctor"); 
X.add("Event"); 
X.add("City"); 
City->Event->Doctor->Boy->Fast
tail    ----- head
top   ---- bottom
top........0

X.addLast("Zoo"); 
X.addFirst("Apple");
Zoo->City->Event->Doctor->Boy->Fast->Apple

X.add (1, "Array");
Zoo->City->Event->Doctor->Boy->Fast->Array->Apple

X.remove("Fast");
Zoo->City->Event->Doctor->Boy->Array->Apple

X.remove (2);
Zoo->City->Event->Doctor->Array->Apple

X.removeFirst ();
Zoo->City->Event->Doctor->Array

X.removeLast ();
City->Event->Doctor->Array

Answer depends on , what each operation means,
Here is how I perceived them:
add("A") -> will append "A" as head to the linked list.
addFirst("A") -> will add "A" as head to the linked list i.e. first element.
addLast("A") -> will append "A" as tail to the linked list.
add (i, "A") -> will add "A" at i th position from head(i=0,1,2,..)
remove("A") ->  will remove "A" from LL
remove(i) -> will remove element from i th position
removeFirst() -> will remove (head)first element from LL.
removeLast() -> will remove (tail)last element from LL.
It will be helpful if you can provide this sort of detail.