void addHRef(PPLH* pplh, char* arg) { char* args[2]; args[0] = strtok(arg,","); args[1] = strtok(NULL,","); int urllen = strlen(args[0]); int desclen = strlen(args[1])-1; char* desc = (char*)malloc(sizeof(char)*desclen); strncpy(desc,args[1],desclen); //HTML char* ahref = "<a href=\""; char* fhref = "</a>\n"; char* hhtml = (char*) malloc(sizeof(char)*urllen+desclen+strlen(ahref)+strlen(fhref)+3); strncat(hhtml,ahref,strlen(ahref)); strncat(hhtml,args[0],urllen); strncat(hhtml,"\">",2); strncat(hhtml,desc,desclen); strncat(hhtml,fhref,strlen(fhref)); insertTail(pplh->html,&hhtml); //LATEX char* hlatex=(char*) malloc(sizeof(char)*urllen+desclen+11); strncat(hlatex,"\\href{",6); strncat(hlatex,args[0],urllen); strncat(hlatex,"}{",2); strncat(hlatex,desc,desclen); strncat(hlatex,"}\n",2); insertTail(pplh->latex,&hlatex); }
void addTexto(PPLH* pplh,char* arg) { char* linha = strdup(arg); //HTML insertTail(pplh->html,&linha); //LATEX insertTail(pplh->latex,&linha); }
void SList::insert(int newData) { SLNode* newNode = new SLNode(newData); if (head == NULL) insertHead(newData); else if (head -> getNextNode() == NULL) { if ((*head).getContents() > newData) insertHead(newData); else insertTail(newData); } else { if (newData <= head -> getContents()) insertHead(newData); else { SLNode* trailer = NULL; SLNode* spot = head; while (spot -> getNextNode() != NULL && newData > spot -> getContents()) { trailer = spot; spot = spot -> getNextNode(); } if (newData > spot -> getContents() && spot -> getNextNode() == NULL) insertTail(newData); else { newNode -> setNextNode(spot); trailer -> setNextNode(newNode); size++; } } } }
/** * 反向存储,即从个位开始 */ ListNode *addTwoNumbers(ListNode *l1, ListNode *l2) { //扫一遍,带carry,然后加上剩余的 ListNode *newHead = new ListNode(0); ListNode *newTail = newHead; int carry = 0; ListNode *p1 = l1; ListNode *p2 = l2; while(p1 && p2){ int val = p1->val + p2->val + carry; updateValueAndCarry(val, carry); insertTail(newTail, val); p1 = p1->next; p2 = p2->next; } while(p1){ int val = p1->val + carry; updateValueAndCarry(val, carry); insertTail(newTail, val); p1 = p1->next; } while(p2){ int val = p2->val + carry; updateValueAndCarry(val, carry); insertTail(newTail, val); p2 = p2->next; } if(carry > 0) insertTail(newTail, carry); return newHead->next; }
void addQuebra(PPLH* pplh) { //HTML char* qhtml = "<br>\n"; insertTail(pplh->html,&qhtml); //LATEX char* qlatex = "\\\\\n"; insertTail(pplh->latex,&qlatex); }
void addAnd(PPLH* pplh) { //HTML char* hand = "&"; insertTail(pplh->html,&hand); //LATEX char* land = "\\&"; insertTail(pplh->latex,&land); }
void addTextoNF(PPLH* pplh) { //HTML char* htmlnf = "<pre>\n"; insertTail(pplh->html,&htmlnf); //LATEX char* latexnf = "\\begin{verbatim}\n"; insertTail(pplh->latex,&latexnf); }
void addComentario(PPLH* pplh) { //HTML char* chtml = "<!--\n"; insertTail(pplh->html,&chtml); //LATEX char* clatex ="\\begin{comment}\n"; insertTail(pplh->latex,&clatex); }
void addModImg(PPLH* pplh) { //HTML char* htmlfigure = "<figure>\n"; insertTail(pplh->html,&htmlfigure); //LATEX char* latexfigure ="\\begin{figure}[!hbp]\n"; insertTail(pplh->latex,&latexfigure); }
void addBackSlash(PPLH* pplh) { //HTML char* hbackshlash = "\\"; insertTail(pplh->html,&hbackshlash); //LATEX char* lbackslash = "\\textbackslash"; insertTail(pplh->latex,&lbackslash); }
void addOrdList(PPLH* pplh) { //HTML char* olhtml = "<ol>\n"; insertTail(pplh->html,&olhtml); //LATEX char* ollatex = "\\begin{enumerate}\n"; insertTail(pplh->latex,&ollatex); }
void addItemList(PPLH* pplh) { //HTML char* ulhtml = "<ul>\n"; insertTail(pplh->html,&ulhtml); //LATEX char* ullatex = "\\begin{itemize}\n"; insertTail(pplh->latex,&ullatex); }
void addEndTAG(PPLH* pplh,char* argHTML,char* argLatex) { //HTML insertTail(pplh->html,&argHTML); //LATEX int latexlen = strlen(argLatex); char* endtaglatex = (char*)malloc(sizeof(char)*latexlen+8); strncat(endtaglatex,"\\end{",5); strncat(endtaglatex,argLatex,latexlen); strncat(endtaglatex,"}\n",2); insertTail(pplh->latex,&endtaglatex); }
void addLinha(Table tabela, Row linha) { Row linhacopia; linhacopia.cells = init(sizeof(Cell),NULL); while(linha.cells->list) { char* celula = pop(linha.cells); insertTail(linhacopia.cells,celula); } insertTail(tabela.rows,&linhacopia); }
bigInteger factorial(unsigned long a) { /* Declarations */ Dlist tmp=malloc(sizeof(Element)); bigInteger result=malloc(sizeof(nb)); bigInteger temp=malloc(sizeof(nb)); unsigned long i,j; char string[11]; char stringr[11]; /* Need to be a unsigned long int */ if(a<0) { return NULL; } /* 0! = 1 */ else if(a==0) { tmp=insertTail(tmp,1); tmp=removeHead(tmp); result->absvalue=tmp; return result; } else { i=1; j=0; /* Make an array of chars with a */ while(a>=i) { string[j]=(a%(i*10)-a%i)/i+'0'; i*=10; j++; } /* Make a bgiInteger with that array */ for(i=0; i<j; i++) { stringr[i]=string[j-i-1]; } stringr[i]='\0'; result=newBigInteger(stringr); /* For k from 1 to a-i, do r=r*k */ for(i=a-1; i>0; i--) { tmp=NULL; tmp=insertTail(tmp,a-i); temp->absvalue=tmp; result=mulBigInt(result,temp); } return result; } }
void addIndice(PPLH* pplh, int nseccao, char* arg) { char* seccao = strdup(arg); int nrDigitsalocar = 2 + nrDigits(nseccao); //2 => \0 + sinal char* taghtml = (char*) malloc(sizeof(char)*nrDigitsalocar); sprintf(taghtml,"%d",nseccao); char* ataghtml = "<a name = \""; char* ftaghtml = "\"></a>\n"; insertTail(pplh->html,&ataghtml); insertTail(pplh->html,&taghtml); insertTail(pplh->html,&ftaghtml); char* aind = "<li><a href=\"#"; char* mind = "\">"; char* find = "</a></li>\n"; insertTail(pplh->seccoes,&aind); insertTail(pplh->seccoes,&taghtml); insertTail(pplh->seccoes,&mind); insertTail(pplh->seccoes,&seccao); insertTail(pplh->seccoes,&find); }
static void test_insertTail(void **state) { const int a = 1001; LinkedList *list = createList(); assert_non_null(list); assert_false(insertTail(NULL, NULL)); int b = 0; assert_false(insertTail(NULL, &b)); for (int i = 0; i < a; i++) { int *c = malloc(sizeof(int)); assert_true(insertTail(list, c)); assert_ptr_equal(peekTail(list), c); } destroyList(list); }
int main(){ int h=0; struct data *head=NULL; struct data *tail=head; struct data *cur=head; char ch; while((ch=getchar()) == 'H' || ch == 'E'); do{ if( ch == 'H' ){ h=1; } else if( ch == 'E' ){ h=0; } else if ( h==1 ){ insertHead(&head,&cur,ch); h=2; } else if (h == 2 ){ insertCur(&cur,ch); } else insertTail(&tail,&head,&cur,ch); }while((ch = getchar()) != '\n'); printLine(&head); return 0; }
/** * insertList * * Insert a new entry either before or after an existing list entry. Paramater * pMember represents the address of the data to be inserted whereas iLocation * identifies the position relative to the existing entry pEntry. * If iLocation is less than zero the new entry is insert BEFORE the existing * entry otherwise it is inserted AFTER the existing entry. * * @note Do NOT test for the specific values like -1, 0 and 1 as different C * implementations and Operating Systems may return different values * when comparing strings. * * @param pMember Address arbitrary data. * @param pEntry Address existing list entry. * @param iLocation Integer identifying the location were the new entry * is to be inserted relative to pEntry. * * @return Address newly allocated list ENTRY struct. **/ ENTRY *insertList( void *pMember, ENTRY *pEntry, int iLocation ) { if( iLocation < 0 ) return insertTail( pMember, (LIST *)pEntry ); else return insertHead( pMember, (LIST *)pEntry ); }
void addItem(PPLH* pplh, char* arg) { int len =strlen(arg); //HTML char* ihtml = (char*)malloc(sizeof(char)*len+11); strncat(ihtml,"<li>",4); strncat(ihtml,arg,len); strncat(ihtml,"</li>\n",6); insertTail(pplh->html,&ihtml); //LATEX char* ilatex = (char*)malloc(sizeof(char)*len+8); strncat(ilatex,"\\item ",6); strncat(ilatex,arg,len); strncat(ilatex,"\n",1); insertTail(pplh->latex,&ilatex); }
Status OrderInsert(poly pointer,Elem e,int (*func)(poly, Elem)) { int result = -1; int count = 0; poly prev = pointer; poly index = pointer; poly tmp = NULL; char *pclFunc = "OrderInsert"; if(LocElem(index,e,func,&result,"compareExpn") == FALSE) { //printf("Not found\n"); tmp = (poly)malloc(sizeof(node)); tmp->data.coef = e.coef; tmp->data.expn = e.expn; while(index != NULL) { if(e.expn < index->data.expn) { tmp->next = prev->next; prev->next = tmp; return; } prev = index; index = index->next; } insertTail(pointer,e); return FALSE; } else { for(count = 0; count < result; count++) { prev = index; index = index->next; } //print(prev); //print(index); if( sum(index->data,e) != 0) { index->data.coef += e.coef; } else { prev->next = index->next; free(index); } //print(index); //printf("\n"); } return TRUE; }
int OrderList::add(ListEntry *node, AddCode where, bool mvcursor) { int status = OLIST_OK; if (node != NULL) { if (f_cursor == NULL) insertNew(node); else { switch (where) { case addAfter: if (f_cursor == f_tail) insertTail(node); else insertAfter(node); break; case addBefore: if (f_cursor == f_head) insertHead(node); else insertBefore(node); break; case addHead: insertHead(node); break; case addTail: insertTail(node); break; default: return OLIST_ERROR; } } if ((mvcursor) || (f_cursor == NULL)) f_cursor = node; } else return OLIST_ERROR; f_size++; return OLIST_OK; }
bigInteger newBigInteger(char nb[]) { /* Declarations */ int i, val; bigInteger temp=NULL; temp=malloc(sizeof(nb)); /* Test : is it 0 or -0 ? */ if((nb[0]=='0'&&nb[1]=='\0')||(nb[0]==45&&nb[1]=='0'&&nb[2]=='\0')) { temp=NULL; } else { /* Negative ? */ if(nb[0]==45) { temp->sign=TRUE; } else { temp->sign=FALSE; } /* Check validity of the number inputed, replace wrong characters by 0 */ for(i=temp->sign; nb[i]!='\0'; i++) { nb[i]=inputToValidNb(nb[i]); } /* make 4 figures' package, until the end of the input */ for(i=i-1; i>=temp->sign; i=i-4) { val=0; if(i>=temp->sign) { val+=nb[i]-'0'; } if(i-1>=temp->sign) { val+=(nb[i-1]-'0')*10; } if(i-2>=temp->sign) { val+=(nb[i-2]-'0')*100; } if(i-3>=temp->sign) { val+=(nb[i-3]-'0')*1000; } /* Insert the package in a DlinkedList, as an element */ temp->absvalue=insertTail(temp->absvalue,val); } } return temp; }
ListNode* reverseBetween(ListNode* head, int m, int n) { if (head == NULL) { return head; } int cnt = 0; ListNode *h1, *t1, *h2, *t2, *h3, *t3; ListNode *p1, *p2; h1 = t1 = NULL; h2 = t2 = NULL; h3 = t3 = NULL; p1 = head; while (p1 != NULL) { ++cnt; p2 = p1; p1 = p1->next; p2->next = NULL; if (cnt < m) { insertTail(h1, t1, p2); } else if (cnt <= n) { insertHead(h2, t2, p2); } else { insertTail(h3, t3, p2); } } if (h1 != NULL) { t1->next = h2; t1 = t2; } else { h1 = h2; t1 = t2; } if (h3 != NULL) { t1->next = h3; t1 = t3; } return h1; }
void SList::insert (int newContents) { if (head == NULL) { insertHead (newContents); } else if (head->getNextNode() == NULL) { if (newContents < head->getContents()) { insertHead(newContents); } else { insertTail(newContents); } } else { SLNode* trailer = NULL; SLNode* leader = head; while (leader->getNextNode() != NULL && newContents > leader->getContents()) { trailer = leader; leader = leader->getNextNode(); } if (leader->getNextNode() == NULL && newContents > leader->getContents()) { insertTail(newContents); } else { SLNode* theNode = new SLNode (newContents); theNode->setNextNode(leader); if (trailer == NULL) { head = theNode; numNodes++; } else { trailer->setNextNode(theNode); numNodes++; } } } }
int main() { // the list's name is "nodolista" insertHead(&nodolista.next, 1); insertTail(&nodolista.next, 6); insertTail(&nodolista.next, 3); insertTail(&nodolista.next, 8); insertTail(&nodolista.next, 4); insertTail(&nodolista.next, 7); insertTail(&nodolista.next, 5); insertTail(&nodolista.next, 9); insertTail(&nodolista.next, 2); // end //printList printList(nodolista.next); //getHead printf("\nHead:\t[ (%d) %d ]\n", getHead(nodolista.next)->index, getHead(nodolista.next)->info); //getTail printf("Tail:\t[ (%d) %d ]\n", getTail(nodolista.next)->index, getTail(nodolista.next)->info); // getPrev int k = 0; printf("Insert an index to return the prev (starting from 0 to %d): ", getIndex(getTail(nodolista.next))); scanf("%d", &k); printf("The prev of value %d is: %d\n", getValue(nodolista.next, k)->info, \ (getPrev(nodolista.next, k) ? getPrev(nodolista.next, k)->info : 0)); // search k = 0; printf("Insert a value to search into the list: "); scanf("%d", &k); printf("The search went: %s\n", (search(nodolista.next, k) ? "true" : "false")); // delete printf("Insert an item in the list to delete: "); scanf("%d", &k); delete(nodolista.next, k); printList(nodolista.next); // inserction sort inserctionSort(nodolista.next); printList(nodolista.next); return 0; } //end main
/*! * \brief encode * \param bufferIn : buffer di dati in ingresso * \param bufferOut : buffer di dati in uscita dove vengono duplicati i DLE ed inoltre * vengono aggiunti i DLE-STX in testa al buffer e DLE-ETX in coda * al buffer */ void encode (const QByteArray &bufferIn, QByteArray &bufferOut) { insertHead(bufferOut); int end = bufferIn.length(); char dato; for (int idx = 0; idx < end; idx++) { dato = bufferIn[idx]; bufferOut.append(dato); // Se il dato da inserire e' il DLE allora lo duplico if (dato == DLE) bufferOut.append(DLE); } insertTail(bufferOut); }
int main(int argc, char*argv[]) { char * p; tlist *plist=createList(); if(plist==NULL) { puts("Kein Speicher"); exit(-1); } int i; tStud* ptmp; while(!quit()) { ptmp=getStud(); insertTail(plist,ptmp); puts("-------------------------"); for(ptmp=getFirst(plist);ptmp;ptmp=getNext(plist)) putStud(ptmp); } return 0; }
void SList::insert (int contents) { if(head == NULL){ insertHead(contents); } else { SLNode* temp=head; SLNode* temp2=temp; while (temp!=NULL && temp->getContents()<contents) { temp2=temp; temp=temp->getNextNode(); } if(temp ==NULL){ insertTail(contents); } else if(temp==head){ insertHead(contents); } else { SLNode* node= new SLNode(contents); node->setNextNode(temp); temp2->setNextNode(node); size++; } } }
// // bool addFunction(f) // Last modified: 02Sep2006 // // Attempts to add the parameterized function to the formation, // returning true if successful, false otherwise. // // Returns: true if successful, false otherwise // Parameters: // f in the function being added // bool Formation::addFunction(const Function f) { return (f != NULL) && insertTail(f); } // addFunction(const Function)