Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/146.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在链接列表中创建链接列表? 我在C++中创建了一个Snake游戏,但是我使用我创建的Link KekLead类有一些麻烦。当我在Python中创建snake时,我在一个列表中创建列表,以表示构成我的snake的每个圆的x和y位置。我正在尝试做类似于C++的事情。这是我制作的模板化linkedList类,如果出于某种原因您需要查看它: #ifndef LLIST_H_INCLUDED #define LLIST_H_INCLUDED #include <cstddef> #include <iostream> using namespace std; template <class T> class linkedList { public: class node { public: ///node class attributes T mPayload; node* mNext; ///constructor node(T toucan):mPayload(toucan),mNext(NULL) {} ///destructor ~node() { ///cascading delete if(mNext) delete mNext; } ///node class methods }; ///linkedList class attributes node* mStart; ///constructor linkedList():mStart(NULL) {} ///destructor ~linkedList() { ///initializes the cascading delete. if(mStart) delete mStart; } ///linkedList class methods T mReturnT(int indx) { if(!mStart) return NULL; else { node* cur; for(int i = 0; i<indx; i++) { if(!cur->mNext) { cout << "Indx out of range. Deleting last item." << endl; break; } cur = cur->mNext; } delete cur; return cur->mPayload; } } void mInsert(int indx, T data) { ///Insert an item at a given position. ///The first argument is the index of ///the element before which to insert. node* cur = mStart; for(int i = 0; i < indx; i++) { if(!cur->mNext) break; else { cur = cur->mNext; } } node* N = new node(data); node* temp = cur->mNext; cur->mNext = N; N->mNext = temp; } T mPop() { ///Removes the last item in the list, ///and returns it. if(!mStart) return NULL; else { node* cur = mStart; while(cur->mNext) { cur = cur->mNext; } T var = cur->mPayload; delete cur; return var; } } int mSize() { if(!mStart) return 0; else { node* cur = mStart; int counter = 1; while(cur->mNext) { cur = cur->mNext; counter++; } delete cur; return counter; } } void mPrint() { ///prints all values in a list. node* cur; if(!mStart) cout << "List is empty." << endl; else { cur = mStart; cout << "["; while(cur) { cout << cur->mPayload << " "; cur = cur->mNext; } cout << "]" << endl; delete cur; } } void swapNodes(node* N) { ///idk } void bubbleSort() { if(!mStart) return; node* cur = mStart; while(cur) { cout << cur->mPayload << endl; if(cur->mRight->mFrequency > cur->mFrequency) { swapNodes(cur); cur = mStart; } else cur = cur->mRight; } delete cur; } }; #endif // LLIST_H_INCLUDED #如果包括 #定义包含的LLIST_H_ #包括 #包括 使用名称空间std; 模板 类链接列表 { 公众: 类节点 { 公众: ///节点类属性 T mpaiload; 节点*mNext; ///建造师 节点(T toucan):mPayload(toucan),mNext(NULL) {} ///析构函数 ~node() { ///级联删除 if(mNext) 删除mNext; } ///节点类方法 }; ///linkedList类属性 node*mStart; ///建造师 linkedList():mStart(NULL) {} ///析构函数 ~linkedList() { ///初始化级联删除。 如果(mStart) 删除mStart; } ///linkedList类方法 T mReturnT(内部索引) { 如果(!mStart) 返回NULL; 其他的 { 节点*cur; for(int i=0;imNext) { 库特姆帕洛德; } } void mInsert(int indx,T数据) { ///在给定位置插入项目。 ///第一个参数是 ///要在其前面插入的元素。 节点*cur=mStart; 对于(int i=0;imNext) 打破 其他的 { cur=cur->mNext; } } 节点*N=新节点(数据); 节点*temp=cur->mNext; cur->mNext=N; N->mNext=温度; } T mPop() { ///删除列表中的最后一项, ///并返回它。 如果(!mStart) 返回NULL; 其他的 { 节点*cur=mStart; while(cur->mNext) { cur=cur->mNext; } T var=cur->mPayload; 删除cur; 收益var; } } int mSize() { 如果(!mStart) 返回0; 其他的 { 节点*cur=mStart; int计数器=1; while(cur->mNext) { cur=cur->mNext; 计数器++; } 删除cur; 返回计数器; } } void mPrint() { ///打印列表中的所有值。 节点*cur; 如果(!mStart) cout_C++_Templates_Linked List - Fatal编程技术网 mNext; } } 节点*N=新节点(数据); 节点*temp=cur->mNext; cur->mNext=N; N->mNext=温度; } T mPop() { ///删除列表中的最后一项, ///并返回它。 如果(!mStart) 返回NULL; 其他的 { 节点*cur=mStart; while(cur->mNext) { cur=cur->mNext; } T var=cur->mPayload; 删除cur; 收益var; } } int mSize() { 如果(!mStart) 返回0; 其他的 { 节点*cur=mStart; int计数器=1; while(cur->mNext) { cur=cur->mNext; 计数器++; } 删除cur; 返回计数器; } } void mPrint() { ///打印列表中的所有值。 节点*cur; 如果(!mStart) cout,c++,templates,linked-list,C++,Templates,Linked List" /> mNext; } } 节点*N=新节点(数据); 节点*temp=cur->mNext; cur->mNext=N; N->mNext=温度; } T mPop() { ///删除列表中的最后一项, ///并返回它。 如果(!mStart) 返回NULL; 其他的 { 节点*cur=mStart; while(cur->mNext) { cur=cur->mNext; } T var=cur->mPayload; 删除cur; 收益var; } } int mSize() { 如果(!mStart) 返回0; 其他的 { 节点*cur=mStart; int计数器=1; while(cur->mNext) { cur=cur->mNext; 计数器++; } 删除cur; 返回计数器; } } void mPrint() { ///打印列表中的所有值。 节点*cur; 如果(!mStart) cout,c++,templates,linked-list,C++,Templates,Linked List" />

如何在链接列表中创建链接列表? 我在C++中创建了一个Snake游戏,但是我使用我创建的Link KekLead类有一些麻烦。当我在Python中创建snake时,我在一个列表中创建列表,以表示构成我的snake的每个圆的x和y位置。我正在尝试做类似于C++的事情。这是我制作的模板化linkedList类,如果出于某种原因您需要查看它: #ifndef LLIST_H_INCLUDED #define LLIST_H_INCLUDED #include <cstddef> #include <iostream> using namespace std; template <class T> class linkedList { public: class node { public: ///node class attributes T mPayload; node* mNext; ///constructor node(T toucan):mPayload(toucan),mNext(NULL) {} ///destructor ~node() { ///cascading delete if(mNext) delete mNext; } ///node class methods }; ///linkedList class attributes node* mStart; ///constructor linkedList():mStart(NULL) {} ///destructor ~linkedList() { ///initializes the cascading delete. if(mStart) delete mStart; } ///linkedList class methods T mReturnT(int indx) { if(!mStart) return NULL; else { node* cur; for(int i = 0; i<indx; i++) { if(!cur->mNext) { cout << "Indx out of range. Deleting last item." << endl; break; } cur = cur->mNext; } delete cur; return cur->mPayload; } } void mInsert(int indx, T data) { ///Insert an item at a given position. ///The first argument is the index of ///the element before which to insert. node* cur = mStart; for(int i = 0; i < indx; i++) { if(!cur->mNext) break; else { cur = cur->mNext; } } node* N = new node(data); node* temp = cur->mNext; cur->mNext = N; N->mNext = temp; } T mPop() { ///Removes the last item in the list, ///and returns it. if(!mStart) return NULL; else { node* cur = mStart; while(cur->mNext) { cur = cur->mNext; } T var = cur->mPayload; delete cur; return var; } } int mSize() { if(!mStart) return 0; else { node* cur = mStart; int counter = 1; while(cur->mNext) { cur = cur->mNext; counter++; } delete cur; return counter; } } void mPrint() { ///prints all values in a list. node* cur; if(!mStart) cout << "List is empty." << endl; else { cur = mStart; cout << "["; while(cur) { cout << cur->mPayload << " "; cur = cur->mNext; } cout << "]" << endl; delete cur; } } void swapNodes(node* N) { ///idk } void bubbleSort() { if(!mStart) return; node* cur = mStart; while(cur) { cout << cur->mPayload << endl; if(cur->mRight->mFrequency > cur->mFrequency) { swapNodes(cur); cur = mStart; } else cur = cur->mRight; } delete cur; } }; #endif // LLIST_H_INCLUDED #如果包括 #定义包含的LLIST_H_ #包括 #包括 使用名称空间std; 模板 类链接列表 { 公众: 类节点 { 公众: ///节点类属性 T mpaiload; 节点*mNext; ///建造师 节点(T toucan):mPayload(toucan),mNext(NULL) {} ///析构函数 ~node() { ///级联删除 if(mNext) 删除mNext; } ///节点类方法 }; ///linkedList类属性 node*mStart; ///建造师 linkedList():mStart(NULL) {} ///析构函数 ~linkedList() { ///初始化级联删除。 如果(mStart) 删除mStart; } ///linkedList类方法 T mReturnT(内部索引) { 如果(!mStart) 返回NULL; 其他的 { 节点*cur; for(int i=0;imNext) { 库特姆帕洛德; } } void mInsert(int indx,T数据) { ///在给定位置插入项目。 ///第一个参数是 ///要在其前面插入的元素。 节点*cur=mStart; 对于(int i=0;imNext) 打破 其他的 { cur=cur->mNext; } } 节点*N=新节点(数据); 节点*temp=cur->mNext; cur->mNext=N; N->mNext=温度; } T mPop() { ///删除列表中的最后一项, ///并返回它。 如果(!mStart) 返回NULL; 其他的 { 节点*cur=mStart; while(cur->mNext) { cur=cur->mNext; } T var=cur->mPayload; 删除cur; 收益var; } } int mSize() { 如果(!mStart) 返回0; 其他的 { 节点*cur=mStart; int计数器=1; while(cur->mNext) { cur=cur->mNext; 计数器++; } 删除cur; 返回计数器; } } void mPrint() { ///打印列表中的所有值。 节点*cur; 如果(!mStart) cout

如何在链接列表中创建链接列表? 我在C++中创建了一个Snake游戏,但是我使用我创建的Link KekLead类有一些麻烦。当我在Python中创建snake时,我在一个列表中创建列表,以表示构成我的snake的每个圆的x和y位置。我正在尝试做类似于C++的事情。这是我制作的模板化linkedList类,如果出于某种原因您需要查看它: #ifndef LLIST_H_INCLUDED #define LLIST_H_INCLUDED #include <cstddef> #include <iostream> using namespace std; template <class T> class linkedList { public: class node { public: ///node class attributes T mPayload; node* mNext; ///constructor node(T toucan):mPayload(toucan),mNext(NULL) {} ///destructor ~node() { ///cascading delete if(mNext) delete mNext; } ///node class methods }; ///linkedList class attributes node* mStart; ///constructor linkedList():mStart(NULL) {} ///destructor ~linkedList() { ///initializes the cascading delete. if(mStart) delete mStart; } ///linkedList class methods T mReturnT(int indx) { if(!mStart) return NULL; else { node* cur; for(int i = 0; i<indx; i++) { if(!cur->mNext) { cout << "Indx out of range. Deleting last item." << endl; break; } cur = cur->mNext; } delete cur; return cur->mPayload; } } void mInsert(int indx, T data) { ///Insert an item at a given position. ///The first argument is the index of ///the element before which to insert. node* cur = mStart; for(int i = 0; i < indx; i++) { if(!cur->mNext) break; else { cur = cur->mNext; } } node* N = new node(data); node* temp = cur->mNext; cur->mNext = N; N->mNext = temp; } T mPop() { ///Removes the last item in the list, ///and returns it. if(!mStart) return NULL; else { node* cur = mStart; while(cur->mNext) { cur = cur->mNext; } T var = cur->mPayload; delete cur; return var; } } int mSize() { if(!mStart) return 0; else { node* cur = mStart; int counter = 1; while(cur->mNext) { cur = cur->mNext; counter++; } delete cur; return counter; } } void mPrint() { ///prints all values in a list. node* cur; if(!mStart) cout << "List is empty." << endl; else { cur = mStart; cout << "["; while(cur) { cout << cur->mPayload << " "; cur = cur->mNext; } cout << "]" << endl; delete cur; } } void swapNodes(node* N) { ///idk } void bubbleSort() { if(!mStart) return; node* cur = mStart; while(cur) { cout << cur->mPayload << endl; if(cur->mRight->mFrequency > cur->mFrequency) { swapNodes(cur); cur = mStart; } else cur = cur->mRight; } delete cur; } }; #endif // LLIST_H_INCLUDED #如果包括 #定义包含的LLIST_H_ #包括 #包括 使用名称空间std; 模板 类链接列表 { 公众: 类节点 { 公众: ///节点类属性 T mpaiload; 节点*mNext; ///建造师 节点(T toucan):mPayload(toucan),mNext(NULL) {} ///析构函数 ~node() { ///级联删除 if(mNext) 删除mNext; } ///节点类方法 }; ///linkedList类属性 node*mStart; ///建造师 linkedList():mStart(NULL) {} ///析构函数 ~linkedList() { ///初始化级联删除。 如果(mStart) 删除mStart; } ///linkedList类方法 T mReturnT(内部索引) { 如果(!mStart) 返回NULL; 其他的 { 节点*cur; for(int i=0;imNext) { 库特姆帕洛德; } } void mInsert(int indx,T数据) { ///在给定位置插入项目。 ///第一个参数是 ///要在其前面插入的元素。 节点*cur=mStart; 对于(int i=0;imNext) 打破 其他的 { cur=cur->mNext; } } 节点*N=新节点(数据); 节点*temp=cur->mNext; cur->mNext=N; N->mNext=温度; } T mPop() { ///删除列表中的最后一项, ///并返回它。 如果(!mStart) 返回NULL; 其他的 { 节点*cur=mStart; while(cur->mNext) { cur=cur->mNext; } T var=cur->mPayload; 删除cur; 收益var; } } int mSize() { 如果(!mStart) 返回0; 其他的 { 节点*cur=mStart; int计数器=1; while(cur->mNext) { cur=cur->mNext; 计数器++; } 删除cur; 返回计数器; } } void mPrint() { ///打印列表中的所有值。 节点*cur; 如果(!mStart) cout,c++,templates,linked-list,C++,Templates,Linked List,这需要是某个东西的链表的链表: linkedList; 大致如下: linkedList< linkedList< something > > p1Snake; linkedListp1Snake; 您的lnkedList类有1个模板化类型T,因此变量定义的语法应该是: linkedList<type> variableName; 您可能想参考这篇题为“链表模板和二叉搜索树”的文章:我将swapNodes和bubbleSort方法从我的链表类中删除。因此

这需要是某个东西的链表的链表:

linkedList;
大致如下:

linkedList< linkedList< something > > p1Snake;
linkedList>p1Snake;

您的
lnkedList
类有1个模板化类型
T
,因此变量定义的语法应该是:

linkedList<type> variableName;

您可能想参考这篇题为“链表模板和二叉搜索树”的文章:

我将swapNodes和bubbleSort方法从我的链表类中删除。因此,现在可以忽略它们。
linkedList< linkedList< something > > p1Snake;
linkedList<type> variableName;
linkedList<linkedList<int> > variableName;