int main() { // does not work with auto yet Stack<int> intVec = makeStack( { 4, 8, 15, 16, 23, 42 }); intVec.add(108); Stack<bool> boolVec = makeStack( { true, false, true }); // bspsw. den enthaltenen vector<bool> innerhalb oeffnen und mit Ctrl(Cmd?)+F nach "flip" suchen Stack<double> deck = makeStack( { 2.71, 3.14 }); deck.add(4.3); }
HashTable makeHashTable(int size) { HashTable tempTable; tempTable.size = size; tempTable.all = new Stack[size]; for (int i = 0; i < size; ++i) { Stack st; makeStack(st); tempTable.all[i] = st; } return tempTable; }
void testStack(){ Stack *s = makeStack(4); push(s, 100); push(s, 20); push(s, 10340); push(s, 10340); printf("%d\n", pop(s)); printf("%d\n", pop(s)); printf("%d\n", pop(s)); printf("%d\n", pop(s)); }
void showMeFact( int n ) { Stack * s = makeStack( NULL ); int i = n; int fact = 1; void ** frameVars; /* * Push all frames onto the stack, emulating the process * that would take place during recursion. */ for( ; i>=0; i-- ) { /* * The next line is included to make clear the role of the base * case test in this iterative implementation. */ if( i == 0 ) break; stackPush( s, 1, (uintptr_t)i ); } /* * Print thet stack after we hit our base cose to see what it * actually looks like. * * We know we hit our base case here, because if we were writing * a fact function recursively, we would stop at 0, which is where * the loop ends. * * Add more calls to stackPrint around the function if you want to * see the state of the stack at different points during the calculation. */ printf( "Stack contents at factorial base case:\n" ); stackPrint( s ); /* * Pop the frames off of our stack, and perform the operation * that we perform on the way back up from our base case. */ for( ; i < n; i++ ) { frameVars = stackPop( s ); printf( "popped:\n" ); fact *= (uintptr_t)frameVars[0]; free( frameVars ); stackPrint( s ); printf( "Intermediate fact value: %d\n\n", fact ); } printf( "\nfact %d: %d\n", n, fact ); }
int main(void) { OPNDType *top1; OPTRType *top2; top1 = (OPNDType *)malloc(sizeof(OPNDType)); top2 = (OPTRType *)malloc(sizeof(OPTRType)); printf("请输入:\n"); makeStack(top1, top2); result(top1); destroyLink(top1, top2); return FALSE; }
int main() { int n; Stack *stack; Key *item; item = (Key*) malloc (sizeof(Key)); int i, j; printf("Enter the size of square:\n"); while((n = getInt()) < 2) { printf("Please enter an integer which is greater than 1\n"); } stack = makeStack(); initialize(stack); for(i = 0; i < n; i++) { for(j = 0; j < n; j++) { item->square[i][j] = 0; } } push(&stack, item); doSomething(&stack, n); //printSquareContent(pop(&stack), n); // for(i = 0; i < 5; i++) { // a->a = i; // push(&stack, a); // } // printf("\n"); // while(!isEmpty(stack)) { // printf("%d\n", pop(&stack)->a); // } free(item); free(stack); return 0; }
void printTrend(BiTree *tree){ int i; BiTreeNode *currentTreeNode = tree->root; TreeStack *treeStack = makeStack(); TreeHeap *treeHeap = makeHeap(tree->size + 1); push(treeStack, currentTreeNode); while(isStackEmpty(treeStack) != 0){ currentTreeNode = pop(treeStack); setHeapElement(treeHeap, currentTreeNode); if(currentTreeNode->right != NULL) push(treeStack, currentTreeNode->right); if(currentTreeNode->left != NULL) push(treeStack, currentTreeNode->left); } makeMaxHeapify(treeHeap); heapSort(treeHeap); fprintf(stdout, "Trending Up:\n"); for(i = treeHeap->size - 1; i >= treeHeap->size - 5; i--) fprintf(stdout, "%s (%+d)\n", getTreeNodeWord(treeHeap->array[i]), getTreeNodeResult(treeHeap->array[i])); fprintf(stdout, "Trending Down:\n"); for(i = 1; i < 6; i++) fprintf(stdout, "%s (%+d)\n", getTreeNodeWord(treeHeap->array[i]), getTreeNodeResult(treeHeap->array[i])); freeHeap(treeHeap); }
int main() { //Opens the program FILE* prog = fopen("input.txt", "r"); //Opens file for program output output = fopen("output.txt", "w"); char list[2000][20]; //Scans program and converts to lexeme list int lexError = scan(prog); fclose(prog); if (lexError == -1) return 0; //Opens lexeme list to be parsed FILE* input = fopen("lexlist.txt", "r"); int size = 0; //Reads lexeme list while(!feof(input)) { fscanf(input, "%s", list[size]); size++; } fprintf(output, "A print out of the token (internal representation) file:\n\n"); int i; for (i = 0; i < size; i++) fprintf(output, "%s ", list[i]); fprintf(output, "\n\nAnd its symbolic representation:\n\n"); symbolRepresent(list, size); fprintf(output, "\n\n"); //Determines if program is syntactically correct and generates intermediate code int correct = program(list, size); if (correct) fprintf(output, "No errors, program is syntactically correct.\n\n"); else { symbolRepresent(list, err); fprintf(output, " ***** "); error(err2); return 0; } //Writes intermediate code to file generateCode(); //Runs intermediate code on virtual machine makeStack(); fclose(input); fclose(output); return 0; }
void Parser::Private::parseError() { Error e; QVector<QVector<Frame> > frames; XauxWhat currentAux; QVector<XauxWhat> auxs; int lastAuxWhat = -1; while (notAtEnd()) { blockingReadNext(); if (reader.isEndElement()) break; if (reader.isStartElement()) lastAuxWhat++; const QStringRef name = reader.name(); if (name == QLatin1String("unique")) { e.setUnique(parseHex(blockingReadElementText(), QLatin1String("unique"))); } else if (name == QLatin1String("tid")) { e.setTid(parseInt64(blockingReadElementText(), QLatin1String("error/tid"))); } else if (name == QLatin1String("kind")) { //TODO this is memcheck-specific: e.setKind(parseErrorKind(blockingReadElementText())); } else if (name == QLatin1String("suppression")) { e.setSuppression(parseSuppression()); } else if (name == QLatin1String("xwhat")) { const XWhat xw = parseXWhat(); e.setWhat(xw.text); e.setLeakedBlocks(xw.leakedblocks); e.setLeakedBytes(xw.leakedbytes); e.setHelgrindThreadId(xw.hthreadid); } else if (name == QLatin1String("what")) { e.setWhat(blockingReadElementText()); } else if (name == QLatin1String("xauxwhat")) { if (!currentAux.text.isEmpty()) auxs.push_back(currentAux); currentAux = parseXauxWhat(); } else if (name == QLatin1String("auxwhat")) { const QString aux = blockingReadElementText(); //concatenate multiple consecutive <auxwhat> tags if (lastAuxWhat > 1) { if (!currentAux.text.isEmpty()) auxs.push_back(currentAux); currentAux.clear(); currentAux.text = aux; } else { if (!currentAux.text.isEmpty()) currentAux.text.append(QLatin1Char(' ')); currentAux.text.append(aux); } lastAuxWhat = 0; } else if (name == QLatin1String("stack")) { frames.push_back(parseStack()); } else if (reader.isStartElement()) { reader.skipCurrentElement(); } } if (!currentAux.text.isEmpty()) auxs.push_back(currentAux); //if we have less xaux/auxwhats than stacks, prepend empty xauxwhats //(the first frame usually has not xauxwhat in helgrind and memcheck) while (auxs.size() < frames.size()) auxs.prepend(XauxWhat()); QVector<Stack> stacks; for (int i = 0; i < auxs.size(); ++i) stacks.append(makeStack(auxs[i], frames[i])); e.setStacks(stacks); emit q->error(e); }
void showMeDepth( int n ) { Stack * s = makeStack( &printTreeVerticalMask ); Tree * t; Tree * tmpNode; int i; char dir; void ** args; /* Populate random tree of size n */ srand( time( 0 ) ); srand( rand( ) ); tmpNode = t = makeTree( ); for( i=1; i<n; i++ ) { while( ( CHILD( tmpNode, /*Choose a random direction at every branch*/ ( dir = rand() % 2 ) ) ) ) tmpNode = CHILD( tmpNode, dir ); if( dir ) tmpNode->right = makeTree( ); else tmpNode->left = makeTree( ); tmpNode = t; } /* End tree generator */ tmpNode = t; while( 1 ) { /* We've reached a leaf */ if( !tmpNode ) { /* Popped last element(head) off the stack */ if( !stackSize( s ) ) break; /* Print it for us(move this or add more for better resolution */ stackPrint( s ); printf( "\n" ); /* Get back to parent */ args = stackPop( s ); switch ((uintptr_t)args[0]) { case 0: /* Been down left side. Visiting right */ stackPush( s, 3, 1, i, args[2] ); tmpNode = ((Tree *)args[2])->right; break; case 1: /* Done with left and right. finish up */ /* i is whatever depth was for right side. left depth is stored in args[1] */ i = 1+ max( (uintptr_t)args[1], i ); tmpNode = NULL; break; } free( args ); continue; } /* If we're still going down a side of the tree, push this node on the stack and continue onward. Worry about depth later */ stackPush( s, 3, 0, 0, tmpNode ); tmpNode = tmpNode->left; /* i is our temp counter for depth. Since we haven't reached the bottom, don't start counting just yet. */ i = 0; } freeTree( t ); printf( "depth: %d\n", i ); }