本文整理汇总了C++中ListPtr::allocateNode方法的典型用法代码示例。如果您正苦于以下问题:C++ ListPtr::allocateNode方法的具体用法?C++ ListPtr::allocateNode怎么用?C++ ListPtr::allocateNode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ListPtr
的用法示例。
在下文中一共展示了ListPtr::allocateNode方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: addMiddleList
int addMiddleList(ListPtr listp,NodePtr position,void* data){ /* Add new Node in the middle of the Queue */
int i=0;
//there is always a previous and a next Node
if(listp->items > 0){
if(position == NULL) {
printf("Position not valid...\n");
return -1;
}
else {
listp->Current = position->previous; //Current is the previous Node
}
listp->Current->next = malloc(sizeof(Node));
listp->Current->next->previous = listp->Current;
listp->Current->next->next = position;
position->previous = listp->Current->next;
listp->allocateNode(&(listp->Current->next->data),data);
listp->Current = listp->Head;
(listp->items)++;
}
else{
printf("List is not properly initialised...\n");
return -1;
}
}
示例2: addLastList
int addLastList(ListPtr listp,void* data){ /* Adds a Node to the end of the List */
int i=0;
if(listp->items == 0){ /* No items yet */
listp->Head = malloc(sizeof(Node));
listp->allocateNode(&(listp->Head->data),data);
listp->Head->next = (Node*) NULL;
listp->Head->previous = (Node*) NULL;
listp->Current = listp->Head;
listp->Last = listp->Head;
(listp->items)++;
return 0;
}
else if(listp->items > 0){
listp->Last->next = malloc(sizeof(Node));
listp->Last->next->previous = listp->Last;
listp->Last = listp->Last->next;
listp->Last->next = (Node*) NULL;
listp->allocateNode(&(listp->Last->data),data);
(listp->items)++;
listp->Current = listp->Last;
return 0;
}
else{
printf("List is not properly initialised...\n");
return -1;
}
}
示例3: addFirstList
int addFirstList(ListPtr listp,void* data){ /* Add new Node as Head of the Queue */
int i=0;
if(listp->items == 0){
listp->Head = malloc(sizeof(Node));
listp->allocateNode(&(listp->Head->data),data);
listp->Head->next = (Node*) NULL;
listp->Head->previous = (Node*) NULL;
listp->Current = listp->Head;
listp->Last = listp->Head;
(listp->items)++;
return 0;
}
else if(listp->items > 0){
listp->Head->previous = malloc(sizeof(Node));
listp->Head->previous->next = listp->Head;
listp->Head = listp->Head->previous;
listp->allocateNode(&(listp->Head->data),data);
listp->Head->previous = (Node*) NULL;
listp->Current = listp->Head;
(listp->items)++;
}
else{
printf("List is not properly initialised...\n");
return -1;
}
}