diff --git "a/2209040080/chapter 2/ex2-10\345\256\236\347\216\260\344\270\244\344\270\252\345\244\232\351\241\271\345\274\217\347\233\270\344\271\230\347\232\204\347\256\227\346\263\225.cpp" "b/2209040080/chapter 2/ex2-10\345\256\236\347\216\260\344\270\244\344\270\252\345\244\232\351\241\271\345\274\217\347\233\270\344\271\230\347\232\204\347\256\227\346\263\225.cpp" new file mode 100644 index 0000000000000000000000000000000000000000..595a3c96f3362546beb4f23271db678aec008ef9 --- /dev/null +++ "b/2209040080/chapter 2/ex2-10\345\256\236\347\216\260\344\270\244\344\270\252\345\244\232\351\241\271\345\274\217\347\233\270\344\271\230\347\232\204\347\256\227\346\263\225.cpp" @@ -0,0 +1,30 @@ +vector DivideMerge::polynomialsMultiply(vector&numA, int lowA, int highA, vector&numB, int lowB, int highB) +{ + vectornumXY,numXYZ; + vectornumX, numY, numZ; + + if (lowA < highA && lowB numa, numb; + int dy; //交叉相乘递归 + numa = polynomialsMultiply(numA, lowA, midA, numB, midB + 1, highB); + numb = polynomialsMultiply(numA, midA + 1, highA, numB, lowB, midB); + numY = crossAdd(numa, midA, highB, numb, highA, midB,dy); //A0*B1+A1*B0 + + int dxy; + numXY = crossAdd(numX, midA, midB, numY, 0, dy, dxy); //A0B0+(A0B1+A1B0) + numZ = polynomialsMultiply(numA, midA + 1, highA, numB, midB + 1, highB); + + int dxyz; + numXYZ = crossAdd(numXY, 0, dxy, numZ, highA, highB,dxyz); + } +else + { + numXYZ.push_back(numA[lowA] * numB[lowB]); + } +} \ No newline at end of file diff --git "a/2209040080/chapter 3/lc \347\224\250\346\240\210\345\256\236\347\216\260\351\230\237\345\210\227.cpp." "b/2209040080/chapter 3/lc \347\224\250\346\240\210\345\256\236\347\216\260\351\230\237\345\210\227.cpp." new file mode 100644 index 0000000000000000000000000000000000000000..f86c20b96fbdf1b08f4eb62fbe181ccf8c715ad9 --- /dev/null +++ "b/2209040080/chapter 3/lc \347\224\250\346\240\210\345\256\236\347\216\260\351\230\237\345\210\227.cpp." @@ -0,0 +1,82 @@ +typedef struct { + int* stk; + int stkSize; + int stkCapacity; +} Stack; + +Stack* stackCreate(int cpacity) { + Stack* ret = malloc(sizeof(Stack)); + ret->stk = malloc(sizeof(int) * cpacity); + ret->stkSize = 0; + ret->stkCapacity = cpacity; + return ret; +} + +void stackPush(Stack* obj, int x) { + obj->stk[obj->stkSize++] = x; +} + +void stackPop(Stack* obj) { + obj->stkSize--; +} + +int stackTop(Stack* obj) { + return obj->stk[obj->stkSize - 1]; +} + +bool stackEmpty(Stack* obj) { + return obj->stkSize == 0; +} + +void stackFree(Stack* obj) { + free(obj->stk); +} + +typedef struct { + Stack* inStack; + Stack* outStack; +} MyQueue; + +MyQueue* myQueueCreate() { + MyQueue* ret = malloc(sizeof(MyQueue)); + ret->inStack = stackCreate(100); + ret->outStack = stackCreate(100); + return ret; +} + +void in2out(MyQueue* obj) { + while (!stackEmpty(obj->inStack)) { + stackPush(obj->outStack, stackTop(obj->inStack)); + stackPop(obj->inStack); + } +} + +void myQueuePush(MyQueue* obj, int x) { + stackPush(obj->inStack, x); +} + +int myQueuePop(MyQueue* obj) { + if (stackEmpty(obj->outStack)) { + in2out(obj); + } + int x = stackTop(obj->outStack); + stackPop(obj->outStack); + return x; +} + +int myQueuePeek(MyQueue* obj) { + if (stackEmpty(obj->outStack)) { + in2out(obj); + } + return stackTop(obj->outStack); +} + +bool myQueueEmpty(MyQueue* obj) { + return stackEmpty(obj->inStack) && stackEmpty(obj->outStack); +} + +void myQueueFree(MyQueue* obj) { + stackFree(obj->inStack); + stackFree(obj->outStack); +} +