当前位置: 首页>>代码示例>>C++>>正文


C++ printStack函数代码示例

本文整理汇总了C++中printStack函数的典型用法代码示例。如果您正苦于以下问题:C++ printStack函数的具体用法?C++ printStack怎么用?C++ printStack使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了printStack函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main()
	{
		struct Stack *s = createStack();
		int i, ele;
		printf("\ttop : %d \n",s->top);
		printf("\t capacity: %d\n", s->capacity);
		for (i=0; i<6; i++)
			{
			push(s, (i+1)*100);
			}
		printf(" \tStsack Elements\n\n");	
		
		printStack(s);
		reverseStack(s);
		printf(" \tStsack Elements after reverse : \n\n");	
		
		printStack(s);
		
			for (i=0; i<6; i++)
			{
			ele= pop(s);
			printf("\nFD stack:%d\n\n",ele);
			}
		printf(" \tStsack Elements\n\n");	
		printStack(s);
		
		
		return 0;
	}
开发者ID:RAJU009F,项目名称:my-work,代码行数:29,代码来源:AStack.c

示例2: testing

void testing(int testArray[], int arrayLength)
{
    int i;
    Stack * stack;
    // create a stack
    stack = createStack();
    // loop for the length of the test data array
    for (i = 0; i < arrayLength; i++)
    {
        //  add an item to the stack
        push(stack, testArray[i]);
        //  print the stack
        printf("List print loop number %d: ", (i+1));
        printStack(stack);
    }
    //    test pop
    printf("Removing the top value from the stack...\n'%d' was just removed from the stack\n", pop(stack));
    //    test peek
    printf("The top value now is: %d\n", peek(stack));
    //    test print stack
    printf("The stack contains the following: ");
    printStack(stack);
    //    test length
    printf("The length of the stack is: %d\n", stackLength(stack));
    //    test destroy stack
    destroyStack(stack);
}
开发者ID:mostafarashed1996,项目名称:CIS-2520,代码行数:27,代码来源:testing.c

示例3: ToH

//void move(char fromPeg, char toPeg, int disk)
//{
//    printf("Move the disk %d from \'%c\' to \'%c\'\n",
//           disk, fromPeg, toPeg);
//}
void ToH(int num_of_disks, char S[], char A[], char D[])
{
	int i;
	char s = 'S';
	char a = 'A';
	char d = 'D';
	int no_of_moves = pow(2, num_of_disks) - 1;
	for(i=num_of_disks;i>=1;i--)
	{
		push(S,i);
	}
	printStack(S);
	for(i = 1; i <= no_of_moves; i++)
	{
		if(i%3==1)
		{
			movedisks(S,D,s,d);
			printStack(D);
		}
	
		else if(i%3==2)
		{
			movedisks(S,A,s,a);
		}
		else
		{
			movedisks(A,D,a,d);
		}
		
	}
	
	
}
开发者ID:shashankgoudp,项目名称:Practice_Programs,代码行数:38,代码来源:Stack_ToH.cpp

示例4: testLib

void testLib() {
  printf("Testing stack library functions...\n");
  Stack s = createStack(3);

  printf("\nCase 1: pushing elements greater than capacity...\n");
  push(0,s); push(1,s);
  push(2,s); push(3,s);
  printStack(s);
  int success = s->top == 2;

  printf("\nCase 2: popping elements greater than length...\n");
  pop(s); pop(s);
  pop(s); pop(s);
  pop(s); pop(s);
  pop(s);
  printStack(s);
//  printf("top = %i\n",s->top);
  success = success && s->top == -1;

  printf("\nCase 3: pushing after having already enqueued and dequeued...\n");
  push(0,s); push(1,s);
  push(2,s); push(3,s);
  push(2,s); push(3,s);
  printStack(s);
//  printf("top = %i\n",s->top);
  success = success && s->top == 2;
  printf("\n");

  freeStack(s);
  if(success) printf("  ☺ success.\n");
  else printf("  ☹ failure.\n");
}
开发者ID:jayrbolton,项目名称:coursework,代码行数:32,代码来源:testProb2.c

示例5: main

int main() {
	int i, j;
	char item[26];

	printf("빈 상태의 스택");
	printStack();

	printf("\n\n스택에 A부터 Z까지 삽입");
	for (i = 65; i < 91; i++) {
		push(i);
	}
	printStack();

	printf("\n\npop으로 역순 출력");
	for (j = 0; j < 26; j++) {
		item[j] = pop();
	}
	printf("\n ");
	for (j = 0; j < 26; j++) {
		printf("%c ", item[j]);
	}

	printf("\n\npop 이후, 빈 상태의 스택");
	printStack();

	system("pause");
	return 0;
}
开发者ID:YG1ee,项目名称:datastructurePr,代码行数:28,代码来源:stackAssignment.c

示例6: main

int main (int argc, char *argv[]) {

  int i = 0;
  Stack *myStack = createStack();
  Node *n = NULL;

  if (myStack == NULL) {
    printf("main: Cannot create stack. Exiting!\n");
    return 0;
  }

  for (i = 0; i < 10; i++) {
    n = createNode(i);
    pushStack(myStack, n);
  }

  printStack(myStack);

  for (i = 0; i < 11; i++) {
    n = popStack(myStack);
    if (n == NULL) {
      printf("main: popped NULL!\n");
      printStack(myStack);
      break;
    }
    printf("main: popped %d\n", n->data);
    free(n);
    n = NULL;
    printStack(myStack);
  }

  return 0;
}
开发者ID:sonesh,项目名称:practice,代码行数:33,代码来源:main.c

示例7: main

int main (void)
{
	Stack * s = createStack();

	int x;
	for (x = 0; x < 5; x++)
		push(s, x);

	printf ("Stack contents: '");
	printStack (s);
	printf ("'\n");

	for (x = 0; x < 2; x++)
	{
		printf ("popped: %d  stack is now: '", pop(s));
		printStack (s);
		printf ("'\n");
	}

	destroyStack (s);
	printf ("Stack contents: '");
	printStack (s);
	printf ("'\n");

	return 0;
}
开发者ID:pzelnip,项目名称:MiscC,代码行数:26,代码来源:StackTest.c

示例8: main

int main() {
  int lenght, i;
  char str[] = "(((a))+(b))(((()()(((()()()))))";
  lenght = strlen(str);

  printStack();

  for(i = 0; i < lenght; i++){

    if(str[i] == '(') {
      push(str[i]);
      printStack();
    } else if(str[i] == ')') {
      pop();
      printStack();
    }
  }

  printStack();

  if (is_empty_stack()) TM_PRINTF("Well done, it was balanced\n", NULL);
  else TM_PRINTF("ooops, stack contains %d elements\n", stack_size);

  return 0;
}
开发者ID:gnomex,项目名称:C-Syllabus,代码行数:25,代码来源:balanced_parentheses.c

示例9: main

int main() {

    push(&stack,1); 
    push(&stack,2);
    push(&stack,3);
    push(&stack,4);
    push(&stack,5);
    printStack(stack);
    pop(&stack);
    pop(&stack);
    printStack(stack);
}
开发者ID:thinkphp,项目名称:computer-science-in-c,代码行数:12,代码来源:myStack.c

示例10: grammarParse

int grammarParse() {
	push('$');
	push('S');
	printf("Rule\t\tStep\tStack\n");
	printf("\t\t0\t$S\n");
	int i = 0;
	char a;
	char x;
	for (i = 0; i < wordlen; ++i){
		a = wordToG(wordIndex[i]);
    FOO:
		x = pop();
		if (isVT(x)) {
			if (x == a){
				printStack();
				printf("\n");
				continue;
			}
			else {
				printf("Error1!The position is %d\n",i);return 0;
			}
		}
		else {
			if (x == '$') {
				if ( x == a) {
					printf("Success\n");break;
				}
				else {
					printf("Error2!The postition is %d\n",i);
					return 0;
				}
			}
			else {
				if (!checkMatrix(x,a,&i)) {
					printf("(x=%c,a=%c)\n", x,a);
					printf("Error3!The postition is %d\n",i);
					return 0;
				}
				else{
					printf("\b");
					printStack();
					printf("\n");
					goto FOO;
				}
			}
		}
		printStack();
		printf("\n");
	}
	return 1;
}
开发者ID:jinjaysnow,项目名称:Jay,代码行数:51,代码来源:test.c

示例11: main

/* function main begins program execution */
int main( void )
{ 
   StackNodePtr stackPtr = NULL; /* points to stack top */
   int choice; /* user's menu choice */
   int value;  /* int input by user */
 
   instructions(); /* display the menu */
   printf( "? " );
   scanf( "%d", &choice );

   /* while user does not enter 3 */
   while ( choice != 3 ) { 

      switch ( choice ) { 

         /* push value onto stack */
         case 1:      
            printf( "Enter an integer: " );
            scanf( "%d", &value );
            push( &stackPtr, value );
            printStack( stackPtr );
            break;

         /* pop value off stack */
         case 2:      

            /* if stack is not empty */
            if ( !isEmpty( stackPtr ) ) {
               printf( "The popped value is %d.\n", pop( &stackPtr ) );
            } /* end if */

            printStack( stackPtr );
            break;

         default:
            printf( "Invalid choice.\n\n" );
            instructions();
            break;

      } /* end switch */

      printf( "? " );
      scanf( "%d", &choice );
   } /* end while */

   printf( "End of run.\n" );

   return 0; /* indicates successful termination */

} /* end main */
开发者ID:AlterTiton,项目名称:bcit-courses,代码行数:51,代码来源:fig12_08.c

示例12: main

int main()
{
	STACK *S;
	S = createStack(5);
 	push(S,7);
    push(S,5);
    push(S,21);
    push(S,-1);
   
    printStack(S);
    pop(S);
    pop(S);
    printStack(S);
    return 0;
}
开发者ID:manitgupta,项目名称:Codes,代码行数:15,代码来源:Stack_using_Arrays.c

示例13: printStack

void SetOfStacks::printStacks() {
    for (int i = 0; i < stacks.size(); i++) {
        std::cout << "Stack " << i+1 << "\n";
        printStack(stacks.at(i));
    }
    std::cout << "\n";
}
开发者ID:hicklin-james,项目名称:CrackingTheCodingInterview,代码行数:7,代码来源:StacksAndQueues3-3.cpp

示例14: functionPrintStack

static EncodedJSValue JSC_HOST_CALL functionPrintStack(ExecState* exec)
{
    // When the callers call this function, they are expecting to print the
    // stack starting their own frame. So skip 1 for this frame.
    printStack(exec, 1);
    return JSValue::encode(jsUndefined());
}
开发者ID:biddyweb,项目名称:switch-oss,代码行数:7,代码来源:JSDollarVMPrototype.cpp

示例15: printStack

void printStack(struct stack * stack ){
    if ( stack == NULL ){
        return ;
    }
    printf("val: %d\n",stack->val);
    printStack(stack->bottom);
}
开发者ID:kizzlebot,项目名称:Computer-Science-I,代码行数:7,代码来源:node.c


注:本文中的printStack函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。