NeighbourUpdate* InitNeighbourUpdates() { NeighbourUpdate* neighbourUpdate = (NeighbourUpdate*)malloc(sizeof(NeighbourUpdate)); neighbourUpdate->m_Pointers = NewStack(); neighbourUpdate->m_Old = NewStack(); return neighbourUpdate; }
DelaunayTriangulation* NewDelaunayTriangulation() { DelaunayTriangulation* dt = (DelaunayTriangulation*)malloc(sizeof(DelaunayTriangulation)); dt->m_AlphaSimplex = nullptr; dt->m_Simplices = NewLinkedList(); dt->m_RemovedSimplices = NewStack(); dt->m_RemovedVoronoiCells = NewStack(); dt->m_Conflicts = NewArrayList(); dt->m_Updates = NewArrayList(); dt->m_NeighbourUpdates = InitNeighbourUpdates(); return dt; }
int main () { stackADT operandStack; string line; char ch; printf("RPN kalkulator -- symulacja (napisz H aby otrzymać pomoc)\n"); operandStack=NewStack(); while (TRUE) { printf("> "); line=GetLine(); ch=toupper(line[0]); switch (ch) { case 'Q': exit(0); case 'H': HelpCommand(); break; case 'C': ClearStack(operandStack); break; case 'D': DisplayStack(operandStack); break; default: if (isdigit(ch)) Push(operandStack, StringToReal(line)); else ApplyOperator(ch, operandStack); break; } } }
UnlambdaEval* NewUnlambdaEval(World* world){ UnlambdaEval* ue; ue = NewObject(UnlambdaEval); ue->fBase.fOne.uObject = (Object*)World_getMemory(world); ue->fBase.fTwo.uObject = (Object*)NewStack(); return ue; }
main(int argc, char *argv[]){ char *t; t = "test"; char *d = ReverseCopy(t); printf("Reversing String now\n"); printf("String:%s\n",d); printf("-------------Question 2--------------\n"); stackADT stack = NewStack(); FILE *in; //char *test = (char *)malloc(256*sizeof(char)), *test2 , *t1; int tM; char *test, *test2 , *t1; int tM; in = fopen("webpage.html","r"); if (in == NULL) printf("Null File my n***a\n"); string t1 = read_a_tag(in); string t2 = read_a_tag(in); /* if (tag_match(read_a_tag(in),read_a_tag(in))){ printf("Testing double method calls\n"); } else{ printf("Did not work\n"); } */ test = read_a_tag(in); printf("Testing read_a_tag method, tag:%s \n",test); test2 = read_a_tag(in); printf("Testing read_a_tag method, tag:%s \n",test2); tM = tag_match(test,test2); printf("Did these tags match?:%d\n", tM); test = read_a_tag(in); t1 = (char *) malloc(strlen(test) * sizeof(char)); if (t1 == NULL) printf("No Memory\n"); t1 = test; printf("Testing read_a_tag method, tag:%s \n",t1); test2 = read_a_tag(in); printf("Testing read_a_tag method, tag:%s \n",test2); tM = tag_match(t1,test2); printf("Did these tags match?:%d\n", tM); fclose(in); }
void toBinary (int input) { StackHndl binStack; binStack = NewStack(); if (input == 0) Push(binStack, 0); while (input >0) { if (input%2 != 0) Push(binStack, 1); else Push(binStack, 0); input = input / 2; } while (!IsEmpty(binStack)) { printf("%d",Top(binStack)); Pop(binStack); } }
int main() { int i = 0; Stack s; NewStack(&s); for(i = 0; i < 10; ++i) { StackPush(&s, i); } for(i = 0; i < s.count; ++i) { printf("the push num is:%d\n", s.array[i]); } FreeStack(&s); return 0; }
void UpdateConflictingSimplicies(Vertex* point, DelaunayTriangulation* dt) { int i; Simplex* simplex = FindContainingSimplex(dt, point); Simplex* current; Stack* toCheck = NewStack(); Push(toCheck, simplex); while (!IsEmpty(toCheck)) { current = (Simplex*)Pop(toCheck); int isDel = IsDelaunay(current,point); if (isDel == -1) { int i = 0; while( isDel == -1 ) { RandomPerturbation(point,i); isDel = IsDelaunay(current,point); i++; } FreeStack(toCheck,nullptr); EmptyArrayList(dt->m_Conflicts); UpdateConflictingSimplicies(point,dt); return; } if ((!isDel) && (!ArrayListContains(dt->m_Conflicts, current))) { AddToArrayList(dt->m_Conflicts, current); for (i = 0; i < 4; i++) if (current->m_NeighbourSimplices[i]) Push(toCheck, current->m_NeighbourSimplices[i]); } } FreeStack(toCheck,nullptr); }
int main() { /*Create an empty stack and variable placeholder*/ int numberRead; StackHndl TheStack; TheStack = NULL; TheStack = NewStack(); printf("Input a non-negative integer to be converted into binary: \n"); while(scanf("%d", &numberRead) == 1) { /*Negative numbers are alerted as errors and not converted*/ if(numberRead < 0) { printf("%d is a negative integer! Try again.\n", numberRead); continue; } /*Zero cases are handled separately*/ if(numberRead == 0) Push(TheStack, 0); /*Loop that iterates down the number*/ while(numberRead > 0) { if(numberRead%2 != 0) Push(TheStack, 1); else Push(TheStack, 0); numberRead = numberRead/2; } /*PRINTING SECTION*/ printf("The binary representation of that is: "); while(!IsEmpty(TheStack)) { printf("%d",Top(TheStack)); Pop(TheStack); } printf("\n"); } FreeStack(&TheStack); return 0; }
ArrayList* FindNeighbours(Vertex* point, Simplex* simplex) { ArrayList* l = NewArrayList(); Stack* toCheck = NewStack(); Simplex* current; Push(toCheck, simplex); while (!IsEmpty(toCheck)) { current = (Simplex*)Pop(toCheck); if ( PointOnSimplex(point, current) && (! ArrayListContains(l, current)) ) { AddToArrayList(l, current); for (int i = 0; i < 4; i++) if (current->m_NeighbourSimplices[i]) Push(toCheck, current->m_NeighbourSimplices[i]); } } FreeStack(toCheck,nullptr); return l; }
/** Starts the sequence of operations that creates the platform specific objects, registers the socket, and initialises the stack. The function is called in the Variant DLL's entry point code, i.e. when the kernel extension is initialised. Note that the Variant DLL is a kernel extension. @return KErrNone if creation and initialisation is successful; one of the other system wide error codes otherwise. @see TMMCardControllerInterface::NewStack() @see TMMCardControllerInterface::NewMediaChange() @see TMMCardControllerInterface::NewVcc() @see TMMCardControllerInterface::Init() @see TMMCardControllerInterface::IsMMCStack() @see TMMCardControllerInterface::MediaChangeID() @see TMMCardControllerInterface::VccID() */ EXPORT_C TInt TMMCardControllerInterface::Create() // // Allocate any resources. Only done once on kernel initialization so don't // worry about cleanup if it fails. // { TInt r=KErrNone; __KTRACE_OPT(KPBUS1,Kern::Printf(">TMMCardControllerInterface::Create")); // Create the password store (a single password store // is allocated for the use of all MMC stacks TMMCPasswordStore* theMmcPasswordStore = (TMMCPasswordStore*)LocDrv::PasswordStore(); if(theMmcPasswordStore == NULL) { theMmcPasswordStore = new TMMCPasswordStore(); if(theMmcPasswordStore) { if((r = theMmcPasswordStore->Init()) == KErrNone) r = LocDrv::RegisterPasswordStore(theMmcPasswordStore); if(r != KErrNone) delete theMmcPasswordStore; } else { r = KErrNoMemory; } } if(r!= KErrNone) return r; r = Init(); if (r != KErrNone) return r; SMediaDeviceInfo mdi; TInt i; for (i=0; i<KMaxPBusSockets && r==KErrNone; i++) { if (IsMMCSocket(i,mdi)) { __KTRACE_OPT(KPBUS1,Kern::Printf("Socket %d is MMC card",i)); // Allocate a new socket DMMCSocket* pS = NewSocket(i, theMmcPasswordStore); if (!pS) { r=KErrNoMemory; break; } TheSockets[i]=pS; // Allocate a variant specific stack object via the interface DMMCStack* pStack=NewStack(i, pS); if (!pStack) { r=KErrNoMemory; break; } pS->iStack=pStack; TInt mcid=MediaChangeID(i); __KTRACE_OPT(KPBUS1,Kern::Printf("Socket %d Media Change %d",i,mcid)); DMMCMediaChange* pM=(DMMCMediaChange*)TheMediaChanges[mcid]; if (!pM) { __KTRACE_OPT(KPBUS1,Kern::Printf("New Media Change")); pM=NewMediaChange(mcid); if (!pM) { r=KErrNoMemory; break; } TheMediaChanges[mcid]=pM; __KTRACE_OPT(KPBUS1,Kern::Printf("Media Change %d at %08x",mcid,pM)); r=pM->Create(); if (r!=KErrNone) break; } else { __KTRACE_OPT(KPBUS1,Kern::Printf("Media Change %d already exists at %08x",mcid,pM)); ++pM->iReplyCount; } TInt vcc=VccID(i); __KTRACE_OPT(KPBUS1,Kern::Printf("Socket %d Vcc %d",i,vcc)); DMMCPsu* pV=(DMMCPsu*)TheVccs[vcc]; if (!pV) { __KTRACE_OPT(KPBUS1,Kern::Printf("New Vcc")); pV=NewVcc(vcc,mcid); if (!pV) { r=KErrNoMemory; break; } TheVccs[vcc]=pV; // Assign Socket here such that iDFc can be obtained pV->iSocket=pS; __KTRACE_OPT(KPBUS1,Kern::Printf("Vcc %d at %08x",vcc,pV)); r=pV->Create(); if (r!=KErrNone) break; } else { __KTRACE_OPT(KPBUS1,Kern::Printf("Vcc %d already exists at %08x, mcid=%d",vcc,pV,pV->iMediaChangeNum)); // DISALLOW SHARED PSUs UNTIL SOMEONE NEEDS THEM // if (pV->iMediaChangeNum!=mcid) // { r=KErrInUse; // break; // } } DMMCPsu* pVCore=(DMMCPsu*)TheVccCores[vcc]; // N.B. Assume paired vcc & vccQ unit are numbered identically! pVCore=NewVccCore(vcc,mcid); if (pVCore) { TheVccCores[vcc]=pVCore; __KTRACE_OPT(KPBUS1,Kern::Printf("VccCore %d at %08x",vcc,pVCore)); // Assign Socket here such that iDFcQ can be obtained pVCore->iSocket=pS; r=pVCore->Create(); if (r!=KErrNone) break; // VccCore must issue sleep instead of power down pVCore->iPwrDownCheckFn = DMMCPsu::SleepCheck; } //else do nothing doesn't matter if its not supported r=pS->Create(mdi.iDeviceName); if (r!=KErrNone) break; pS->iMediaChangeNumber=mcid; pS->iMediaChange=pM; pS->iVcc=pV; if (pVCore) { pS->iVccCore = pVCore; } r=pS->Init(); if (r!=KErrNone) break; r = RegisterMediaDevices(i); if(r != KErrNone) break; __KTRACE_OPT(KPBUS1,Kern::Printf("Socket %d Created OK",i)); } else __KTRACE_OPT(KPBUS1,Kern::Printf("Socket %d not MMC card",i)); } __KTRACE_OPT(KPBUS1,Kern::Printf("<TMMCardControllerInterface::Create, ret %d",r)); return r; }
MatrixStack2D *NewMatrixStack2D() { return NewStack(32, sizeof(Matrix2D)); }
MatrixStack3D *NewMatrixStack3D() { return NewStack(32, sizeof(Matrix3D)); }