//Generates the FIRST array void GenerateFirst(struct First *__ptrInput, struct Grammar *__ptrGrammar){ struct internals *_ptrInternals = (struct internals *)__ptrInput->internals; InitFirstArray(__ptrInput, __ptrGrammar); while (AddFirst(__ptrInput, __ptrGrammar)!=0){ } }
bool CDoubleList::AddAfter( CDoubleLink *pPrev, CDoubleLink *pItem ) { // If previous is NULL -- add to first if ( pPrev == NULL ) return AddFirst( pItem ); if ( pItem == NULL || pItem->m_pList ) return (false); // In a list or NULL -- don't add! if ( pPrev->m_pList != this ) return (false); // Previous is not our list! pItem->m_pNext = pPrev->m_pNext; pItem->m_pPrev = pPrev; if ( pPrev->m_pNext ) pPrev->m_pNext->m_pPrev = pItem; pPrev->m_pNext = pItem; if ( m_pLast == pPrev ) m_pLast = pItem; // Remember our list pItem->AddToList( this ); // Update item count m_itemCount++; return (true); }
void SrpcGateHandlerRegistry::add(const char* szCallName, ApSRPCCallback fnHandler) { SrpcGateHandlerRegistrant* p = new SrpcGateHandlerRegistrant(szCallName, fnHandler); if (p != 0) { AddFirst(p); } }
template <typename T> const ZsfLinkedListItm<T> *ZsfLinkedList<T>::Add(int index, T *value) { if (index) { const ZsfLinkedListItm<T> *item = Node(index-1); return InsertAfter(item, value); } else { return AddFirst(value); } }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // Tries to add the specified node to the list. If the maximum number // of objects is reached, the object is not added and it's address // is returned, otherwise 'nullptr' is returned. // Note that this doesn't take the lock! NodeType* AddObjectUnlocked(NodeType* node) { if(Count < maxObjects_) { AddFirst(node); return nullptr; } return node; }
void AddLast(LinkedList *pLinkedList, Node *pNewNode) { Node *node = pLinkedList->head; if (node == NULL) { AddFirst(pLinkedList, pNewNode); return; } while (node->next != NULL) { node = node->next; } node->next = pNewNode; }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // Tries to make the specified block the active one. // If the specified block has fever objects than the active one, // or the active one has more than 25% free objects, the block // is put on the second position. void MakeBlockActive(BlockHeader* block) { if(First() == nullptr) { AddFirst(block); // The First() block in the list. } else { unsigned int firstFree = static_cast<BlockHeader*>(First())->FreeObjects; if((firstFree <= (MaxObjectNumber() / 4)) && (block->FreeObjects > firstFree)) { // Few unused objects are in the active block, // and this one has more unused objects, so make it active. Remove(block); AddFirst(block); } else { // Add the block after the active one. Remove(block); AddAfter(First(), block); } } }
List* ADB_Insert(List *L) { DATA temp; cout << "Please input the info of the poeple." << endl; cout << "name: "; cin >> temp.name; cout << "address: "; cin >> temp.addr; cout << "phone: "; cin >> temp.phone; L->first = AddFirst(L, temp); return L; }
int main() { FILE *pf_in=fopen("input.dat", "r"); FILE *pf_out=fopen("output.dat", "w"); char action[20]; int value; while(fscanf(pf_in,"%s %d", &action, &value)!=EOF) { if((strcmp(action,"AF"))==0) { AddFirst(value); } if((strcmp(action,"AL"))==0) { AddLast(value); } if((strcmp(action,"DF"))==0) { DelFirst(); } if((strcmp(action,"DL"))==0) { DelLast(); } if((strcmp(action,"DOOM_THE_LIST"))==0) { DoomList(); } if((strcmp(action,"DE"))==0) { DeleteCertainElement(value); } if((strcmp(action,"PRINT_ALL"))==0) { PrintAll(pf_out); } if((strcmp(action,"PRINT_F"))==0) { PrintFirst(value, pf_out); } if((strcmp(action,"PRINT_L"))==0) { PrintLast(value, pf_out); } } fclose(pf_in); return 0; }
int main() { FILE *p; p=fopen("input.dat","r"); o=fopen("output.dat","w"); char a[100],*c,*d; while(fgets(a,100,p)) { c=strtok(a," \n"); d=strtok(NULL," \n"); if(strcmp(c,"AF") == 0) { AddFirst(atoi(d), &Works); } else if (strcmp(c,"AL") == 0) { AddLast(atoi(d), &Works); } else if(strcmp(c,"DF")==0) { DeleteFirst(&Works); } else if(strcmp(c,"DL")==0) { DeleteLast(&Works); } else if(strcmp(c,"DE")==0) { DeleteElement(atoi(d), &Works); } else if(strcmp(c,"PRINT_ALL")==0) { print(&Works); } else if(strcmp(c,"PRINT_F")==0) { PrintNrOfElements(atoi(d), &Works); } else if(strcmp(c,"PRINT_L")==0) { PrintNrOfElementsLast(atoi(d), &Works); } else if(strcmp(c,"DOOM_THE_LIST")==0) { Doom(&Works); } } return 0; }
int main() { FILE *f1=fopen("input.dat","r"); FILE *f2=fopen("output.dat","w"); char s[15]; int data; p->head=0; p->tail=0; while(fscanf(f1, "%s", s)==1) { if(strcmp(s, "AF")==0) { fscanf(f1, " %d", &data); AddFirst(data); } if(strcmp(s, "AL")==0) { fscanf(f1, " %d", &data); AddLast(data); } if(strcmp(s, "DF")==0) DeleteFirst(); if(strcmp(s, "DL")==0) DeleteLast(); if(strcmp(s, "DE")==0) { fscanf(f1, "%d", &data); DeleteElem(data); } if(strcmp(s, "DOOM_THE_LIST")==0) Doom_The_List(); if(strcmp(s, "PRINT_ALL")==0) PrintAll(f2); if(strcmp(s, "PRINT_F")==0) { fscanf(f1, "%d", &data); PrintFirst(data, f2); } if (strcmp(s,"PRINT_L")==0) { fscanf(f1, "%d", &data); PrintLast(p->tail, data, f2); fprintf(f2, "\n"); } } return 0; }
void AddNodeByIndex(LinkedList *pLinkedList, int index, Node *pNewNode) { if (index < 0) return; if (index == 0) { AddFirst(pLinkedList, pNewNode); return; } Node *node = pLinkedList->head; if (node == NULL) return; /* if index > 0 && head == NULL, this is a error. In this case, index should be 0 anyway while head == NULL*/ /* Below head != NULL and index >= 1 */ while (--index) { node = node->next; if (node == NULL) return; /* index > size of linked list*/ } pNewNode->next = node->next; node->next = pNewNode; }
int main() { char strng[20]; int value; FILE *d; d= fopen("input.dat", "r"); while(fscanf(d, "%s %d", &strng, &value)!=EOF) { if (strcmp(strng,"AF")==0) AddFirst(value); if (strcmp(strng,"AL")==0) AddLast(value); if (strcmp(strng,"PRINT_ALL")==0) print_list(); if (strcmp(strng,"DF")==0) DelFirst(); if (strcmp(strng,"DL")==0) DelLast(); if (strcmp(strng,"DOOM_THE_LIST")==0) DoomTheList(); if (strcmp(strng,"DE")==0) DelAnElement(value); if (strcmp(strng,"PRINT_F")==0) PRINT_F(value); if (strcmp(strng,"PRINT_L")==0) PRINT_L(value); } fclose(d); return 0; }
struct ParseTreeNode * Add_Next(struct ParseTree *__ParseTree,struct ParseTreeNode *__Node, void *__newValue){ struct ParseTreeNode *_ptrTemp; struct ParseTreeNode *_ptrNew; struct internals *_ptrInternals = (struct internals *)__ParseTree->internals; _ptrTemp =AddFirst(__ParseTree, __Node, __newValue); if (_ptrTemp!=NULL){ return _ptrTemp; } _ptrNew = (struct ParseTreeNode*)malloc(sizeof(struct ParseTreeNode)); _ptrNew->Value = (void*)malloc(sizeof(_ptrInternals->size)); _ptrNew->FirstChild =NULL; _ptrNew->Next = NULL; _ptrNew->Parent = __Node->Parent; memcpy(_ptrNew->Value, __newValue,_ptrInternals->size); __Node->Next = _ptrNew; return _ptrNew; }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void AddNewBlock(BlockHeader* block) { AddFirst(block); }