#define MAX (10) int main() { Init(); int i; for (i = 0; i < MAX; ++i) { Insert(i); } for (i = 0; i < MAX; ++i) { printf("Search:%d %s\n", i, Search(i) == true? "Success" : "Failure"); } printf("\n");
Delete(4); Delete(9); Delete(1); for (i = 0; i < MAX * 2; ++i) { printf("Search:%d %s\n", i, Search(i) == true? "Success" : "Failure"); }
#include <stdio.h> #include <string.h> #include <string> #include <map> #include <vector> #include <algorithm> #define MAX (100) using std::map; using std::string; using std::vector; using std::sort;
void pop() { if (nTime % 2) { while (!one.empty()) { T t = one.front(); one.pop(); if (!one.empty()) { two.push(t); } } } else { while (!two.empty()) { T t = two.front(); two.pop(); if (!two.empty()) { one.push(t); } } }
nTime = (nTime + 1) % 2; --nSize; }
T& top() { if (nTime % 2) { while (!one.empty()) { T t = one.front(); one.pop(); if (!one.empty()) { two.push(t); } else { two.push(t); nTime = (nTime + 1) % 2; return two.back(); } } } else { while (!two.empty()) { T t = two.front(); two.pop(); if (!two.empty()) { one.push(t); } else { one.push(t); nTime = (nTime + 1) % 2; return one.back(); } } } }
bool empty() { return nSize == 0; }
private: queue<T> one; queue<T> two; int nSize; int nTime; };
#define MAX 20
int main() { CStack<int> stack;
for (int i = 0; i < MAX; ++i) { stack.push(i); }
while (!stack.empty()) { printf("top: %d\n", stack.top()); stack.pop(); }
#include <stdio.h> #include <string.h> #include <algorithm> #define MAX (1024 + 10) using namespace std; int nInput[MAX]; void GetNext(int* nInput, int nLen) { int i = nLen - 2; while (i >= 0) { if (nInput[i] >= nInput[i + 1]) { --i; } else { int k = i + 1; for (int j = nLen - 1; j > i; --j) { if (nInput[j] > nInput[i] && nInput[j] < nInput[k]) { k = j; } } swap(nInput[i], nInput[k]); sort(nInput + i + 1, nInput + nLen); return; } }
sort(nInput, nInput + nLen); } int main() { int nCases; scanf("%d", &nCases); while (nCases--) { int nLen; int nK; scanf("%d%d", &nLen, &nK); for (int i = 0; i < nLen; ++i) { scanf("%d", &nInput[i]); } for (int i = 0; i < nK; ++i) { GetNext(nInput, nLen); } for (int i = 0; i < nLen; ++i) { printf("%d%s", nInput[i], i == nLen - 1 ? "\n" : " "); } } return 0; }