int main() { pst head = NULL; printf("vvedyte vyrazhenye\n"); char s[60]; scanf("%s", s); int length = strlen(s); for(int i = 0; i < length; i++) { if (!isSymbol(s[i])) push(head, s[i] - '0'); else if (isSymbol(s[i])) { int a = front(head); pop(head); int b = front(head); pop(head); push(head, makeOperation(s[i], a, b)); } } printf("result = "); printf("%d\n",front(head)); deleteStack(head); return 0; }
int main(int argc, char *argv[]) { int i, len; char buf[1000]; FILE *f; struct stack s; char *tmp; initStack(&s); if (argc == 2) { f =fopen(argv[1], "r"); //open with read only mod if ( f == NULL) { printf("file open fail, please check filename and privilege\n"); return 1; } while (fscanf(f, "%s", buf) != EOF) { addStack(&s, buf); } while(!emptyStack(&s)) { printf("%s\n", tmp=deleteStack(&s)); free(tmp); //用完再釋出記憶體空間 } } else { printf("please specify filename as the first argument\n"); } return 0; }
/// Function name : treeprocResolveGameStringSubstrings // Description : Resolve lookup sub-strings in the specified GameString. Copy mission sub-strings verbatim, // and delete comment sub-strings entirely. // // AVL_TREE_NODE* pNode : [in] Node containing a GameString // AVL_TREE_OPERATION_DATA* pOperationData : [in] xFirstInput : ERROR_QUEUE* : [in/out] Failure queue // VOID treeprocResolveGameStringSubstrings(AVL_TREE_NODE* pNode, AVL_TREE_OPERATION* pOperationData) { GAME_STRING* pGameString; // Convenience pointer TCHAR* szOutput; // Output string containing resolved sub-strings LIST* pResolutionList; // Prepare pGameString = extractPointerFromTreeNode(pNode, GAME_STRING); // [CHECK] Abort if string contains no special characters if (findNextNonEscapedCharacters(pGameString->szText, TEXT("({")) == NULL) return; // Prepare szOutput = utilCreateEmptyString(MAX_STRING); pResolutionList = createStack(NULL); /// Attempt to resolve sub-strings. Increment running total of failures. pOperationData->xOutput += resolveGameStringSubStrings(pGameString, szOutput, MAX_STRING, pResolutionList, pOperationData->pErrorQueue); // Replace GameString text pGameString->szText = utilReplaceString(pGameString->szText, szOutput); pGameString->iCount = lstrlen(pGameString->szText); // [RESOLVED] Mark as resolved pGameString->bResolved = TRUE; // Cleanup deleteStack(pResolutionList); utilDeleteString(szOutput); }
int isPathDfs(Graph g, Vertex v, Vertex w) { int isPath = FALSE; Stack s = newStack(); // create a new stack Vertex currentVertex = 0; int *visited = calloc(g->nV, sizeof(int)); // allocate + init to 0 int i = 0; assert(visited != NULL); push(s, v); // push first vertex onto stack visited[v] = TRUE; // mark it as visited while ( !isEmptyStack(s) ){ // still have vertices to traverse currentVertex = pop(s); // get a vertex from the stack printf("Visiting: %d\n", currentVertex); visited[currentVertex] = TRUE; // mark it as visited if (currentVertex == w) { isPath = TRUE; } for (i = 0; i < g->nV; i++){ // search for a vertex we haven't visited if (g->edges[currentVertex][i] && !visited[i]){ // ignore pendants push(s, i); // push vertex onto stack visited[i] = TRUE; } } } free(visited); deleteStack(s); return isPath; }
int main() { Stack* s=createStack(); push(s,1); int data = pop(s); printf("%d", data); deleteStack(s); return 0; }
int main(void){ Stack * stack; char * tempValue; int i; printf("\nCreating a new Stack"); stack = createStack("1"); tempValue = malloc(sizeof(char) * 128); for(i=2;i<101;i++){ sprintf(tempValue,"%d",i); stack = addToStack(tempValue,stack); } printf("\nThe value of the element on top of the stack is: %s",getTopValue(stack)); printf("\nPrinting the stack"); printStack(stack); printf("\nRemoving the top element of the stack, and printing again"); stack = removeFromTop(stack); printStack(stack); printf("\nThe value of the element on top of the stack is: %s",getTopValue(stack)); printf("\nDeleting the stack, and then printing again"); stack = deleteStack(stack); printStack(stack); printf("\nThe value of the element on top of the stack is: %s",getTopValue(stack)); printf("\nAttempting to delete an empty stack"); stack = deleteStack(stack); printf("\nAttempting to remove the top element of an empty stack"); stack = removeFromTop(stack); printf("\nAttempting to add an element to an empty stack"); stack = addToStack("1",stack); printf("\nThe value of the element on top of the stack is: %s",getTopValue(stack)); printf("\nPrinting the stack"); printStack(stack); printf("\nAdding an element with an empty value"); stack = addToStack(NULL,stack); printf("\nThe value of the element on top of the stack is: %s",getTopValue(stack)); printf("\nPrinting the stack"); printStack(stack); printf("\n"); return(0); }
int main() { Stack *s = stackInit(); push(s, 4); push(s, 2); push(s, 6); push(s, 9); push(s, 7); while (!isStackEmpty(s)) { fprintf(stdout, "%d\n", pop(s)); } deleteStack(s); return 0; }
bool ParseOS2( void ) /*******************/ { parse_stack resource_state; p_action what; newParseStack( &resource_state ); what = doParse( &resource_state ); if( what == P_ERROR ) { RcError( ERR_PARSER_INTERNAL ); ErrorHasOccured = true; } deleteStack( &resource_state ); return( what != P_ACCEPT ); }
int main() { setlocale(LC_ALL, "Rus"); char str[100]; char temp = 0; bool hasBalance = true; printf("¬ведите последовательность скобок:\n"); scanf("%s", &str); Stack *stack = createStack(); for (int i = 0; i < strlen(str); i++) { if (str[i] == '(' || str[i] == '{' || str[i] == '[') push(stack, str[i]); if (str[i] == '}' || str[i] == ')' || str[i] == ']') { temp = pop(stack); if (str[i] == ')') if (temp != '(') { hasBalance = false; break; } if (str[i] == '}') if (temp != '{') { hasBalance = false; break; } if (str[i] == ']') if (temp != '[') { hasBalance = false; break; } } } int a = pop(stack); if (a != NULL || !hasBalance) printf("Ѕаланса скобок нет\n"); else printf("Ѕаланс скобок\n"); deleteStack(stack); return 0; }
int main(){ linkedlistStack* s=create(); int i,size=5; char a[20]; printf("input a string\n"); scanf("%s",a); i=0; while(a[i]!='\0'){ push((char)a[i],s); i++; } printf("no. of elements pushed %d", i); while(s->top!=NULL){ printf("%c",(char)pop(s)); //scanf("%d",&i); } deleteStack(s); return 0; }
//===================================================================== int main() { char c; int a = 0, g, p; Stack_t *stack = createStack(); FILE *mf; mf = fopen ("my.forcpu","r"); while(1) { c = fgetc(mf); if(c == EOF) break; if(c == ' ') a++; } fclose(mf); mf = fopen ("my.forcpu","r"); while(a) { fscanf(mf, "%d", &p); if(p == cmd_Push) PUSH; if(p == cmd_Pop) POP; if(p == cmd_Add) ADD; if(p == cmd_Sub) SUB; if(p == cmd_Mul) MUL; if(p == cmd_Div) DIV; a--; } printf("%d ", pop(stack)); deleteStack(&stack); return 0; }
int main() { node* stack; createStack(&stack); push(&stack, 1); push(&stack, 2); push(&stack, 23); push(&stack, 24); printStack(stack); pop(&stack); pop(&stack); pop(&stack); pop(&stack); printStack(stack); push(&stack, 1); push(&stack, 32); push(&stack, 43); printStack(stack); deleteStack(&stack); printStack(stack); return 0; }
LinkedStack::~LinkedStack() { deleteStack(); delete head; }
arrayStack::~arrayStack() { deleteStack(); }
StackListImplementation::~StackListImplementation(void) { deleteStack(); }