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


C++ MyStack类代码示例

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


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

示例1: MyStack

int Graph::_GetComponentAff(double *A,int size,bool * node_list,int i,int * row)
{
	MyStack * stack;
	int n=0,j,tmp,k;

	stack = new MyStack(size);
	row[n++] = i;
	stack->stack_push(i,0);

	while(stack->stack_pop(&j,&tmp)!=-1)
	{
		for(k=0;k<size;k++)
		{
			if(A[j*size+k]>0.0000001 && node_list[k]==false)
			{
				row[n++] = k;
				stack->stack_push(k,0);
				node_list[k] = true;
			}
		}
	};
	row[n] = -1;

	delete stack;
	return n+1;
}
开发者ID:ColumbiaDVMM,项目名称:INDetector,代码行数:26,代码来源:Graph.cpp

示例2: _GetComponent

int Graph::_GetComponent(int i,int * row)
{
	MyStack * stack;
	int n=0,j,tmp,result[1000],result_e[1000],neib_no=0,k;

	stack = new MyStack;
	row[n++] = i;
	stack->stack_push(i,0);

	while(stack->stack_pop(&j,&tmp)!=-1)
	{
		neib_no = GetNeighborNodeAndEdge(j, result,result_e);
		for(k=0;k<neib_no;k++)
		{
			if(node_list[result[k]].color==0 && edge_list[result_e[k]].weight > 0.5)  // hasn't been dried
			{
				row[n++] = result[k];
				stack->stack_push(result[k],0);
				node_list[result[k]].color=1;
			}
		}
	};
	row[n] = -1;
	delete stack;
	return n;
}
开发者ID:ColumbiaDVMM,项目名称:INDetector,代码行数:26,代码来源:Graph.cpp

示例3: PreTraverse

//先序
void MyTree::PreTraverse(TreeNode* pNode)
{
//   if(pNode == NULL)
//   {
//     return;
//   }
// 
//   printf("%d ", pNode->m_Data);
//   PreTraverse(pNode->m_pLeft);
//   PreTraverse(pNode->m_pRight);
  
  MyStack<TreeNode*> ss;
  TreeNode* pCur = pNode;

  do
  {
    while(pCur)
    {
      printf("%d ", pCur->m_Data);
      ss.push(pCur);
      pCur = pCur->m_pLeft;
    }
    
    if(!ss.IsEmpty())
    {
      pCur = ss.pop();
      pCur = pCur->m_pRight;
    }
  }while(pCur || !ss.IsEmpty());
  
}
开发者ID:styxschip,项目名称:Note,代码行数:32,代码来源:MyTree.cpp

示例4: char_test

void char_test()
{
  char next;

  MyStack<char> s;

  cout << "Enter some text\n";

  // read characters in one by one until newline reached

  cin.get(next);
  while (next != '\n') {

    // push latest character

    s.push(next);
    cin.get(next);
  }

  cout << "Written backward that is:\n";

  // output all characters stored in stack

  while (!s.empty())
    cout << s.pop();
  cout << "\n";

}
开发者ID:aszos,项目名称:SchoolWork,代码行数:28,代码来源:main.cpp

示例5: string_test

void string_test()
{
  string next;
  char c;

  MyStack<string> s;

  cout << "Enter a sentence or two\n";

  // read from terminal word by word

  while (cin >> next) {

    // put latest word into stack

    s.push(next);

    // was that the last word on the line?

    c = cin.get();

    if (c == '\n')
      break;
    else
      cin.putback(c);

  }

  cout << "Written backward that is:\n";
  
  while (!s.empty())
    cout << s.pop() << " ";
  cout << "\n";

}
开发者ID:aszos,项目名称:SchoolWork,代码行数:35,代码来源:main.cpp

示例6: main

int main()
{
	cout<<"----------MyStack<int>---------------"<<endl;
	MyStack<int> mysatck;
	mysatck.push(1);
	mysatck.push(2);
	mysatck.push(3);
	cout<<mysatck.pop()<<endl;
	cout<<mysatck.pop()<<endl;
	cout<<mysatck.pop()<<endl;

	cout<<"----------deque<int>---------------"<<endl;
	deque<int> dequeint;
	dequeint.push_front(1);
	dequeint.push_front(2);
	dequeint.push_front(3);
	
	cout<<dequeint.front()<<endl;
	dequeint.pop_front();
	cout<<dequeint.front()<<endl;
	dequeint.pop_front();
	cout<<dequeint.front()<<endl;
	dequeint.pop_front();
	return 0;
}
开发者ID:dinodragon,项目名称:mygooglecode,代码行数:25,代码来源:Main.cpp

示例7: NODE_PTR

// reachability test, from ni -> nj, according to weight
bool Graph::Reachable(int ni, int nj)
{
	MyStack * stack;
	int tmp,result[1000],result_e[1000],neib_no=0,k;
	int nt,i;

	for(i=0;i<node_num;i++)
		NODE_PTR(i)->color = 0;

	stack = new MyStack;
	stack->stack_push(ni,0);
	NODE_PTR(i)->color = 1;

	while(stack->stack_pop(&nt,&tmp)!=-1)
	{
		neib_no = GetNeighborNodeAndEdge(nt, result,result_e);
		for(k=0;k<neib_no;k++)
		{
			if(result[k]==nj && EDGE_PTR(result_e[k])->weight > 0.5)
			{
				delete stack;
				return true;
			}
				
			if(NODE_PTR(result[k])->color==0 && EDGE_PTR(result_e[k])->weight > 0.5)  // hasn't been dried
			{
				stack->stack_push(result[k],0);
				NODE_PTR(result[k])->color=1;
			}
		}
	};
	delete stack;

	return false;
}
开发者ID:ColumbiaDVMM,项目名称:INDetector,代码行数:36,代码来源:Graph.cpp

示例8: sortTokenByStacks

/* Function: sortTokenByStacks()
 * Usage: is called by formulaStringScanning() for single token;
 * -----------------------------------------------------------------------------------------//
 * Sort this token through the stacks. If token is number - push it to stackNumbers.
 * If token is valid operator token - process it due to Shunting-Yard conditions.
 *
 * @param token             Current token in formula string
 * @param stackNumbers      Stack of number values for current recursion
 * @param stackOperators    Stack of operators for current recursion */
void sortTokenByStacks(string token,
                       MyStack<double> &stackNumbers,
                       MyStack<string> &stackOperators) {
    if(stringIsDouble(token)) { //Token is number
        double num = stringToDouble(token);
        stackNumbers.push(num);//Just save token to stack
    } else { // Token is operator
        /* Main operators process */
        if(stackOperators.isEmpty()) { //Empty - push there without conditions
            stackOperators.push(token);
        } else { //If there are some operators in stack
            string topOper = stackOperators.peek();//Get top operator
            if(getOperPrecedence(topOper) < getOperPrecedence(token)) {
                /* Top operator precednce is
                 * weaker then this token operator - just save this token */
                stackOperators.push(token);
            } else {
                /* Top operator precednce is higher - evaluate two top numbers
                 * with top operator, and sort current token again */
                if(!failFlag) { //If there some fails - break this function
                    /* Main calculation for top numbers and top operator  */
                    twoNumsProcess(stackNumbers, stackOperators);
                    /* Call sorting again to process current token operator  */
                    sortTokenByStacks(token, stackNumbers, stackOperators);
                }
            }
        }
    }
}
开发者ID:ekuryatenko,项目名称:cs-b-assignment3_Calculator,代码行数:38,代码来源:Calculator.cpp

示例9: solveMas

bool solveMas(string s)
{
	MyStack<char> st;
	char skob[3][2];
    skob[0][0] = '(';
    skob[1][0] = '[';
    skob[2][0] = '{';
    skob[0][1] = ')';
    skob[1][1] = ']';
    skob[2][1] = '}';

    for (int i = 0 ; i < s.size() ; i++) {
        char c = s[i];
        int curJ = -1, curK;
        for (int j = 0 ; j < 3 ; j++) {
        	for (int k = 0 ; k < 2 ; k++) {
        		if (skob[j][k] == c) {
        			curJ = j, curK = k;
        			break;
        		}
        	}
        	if (curJ != -1)
        		break;
        }
        if (curK == 1) {
        	if (!st.sz || st.front() != skob[curJ][0]) {
        		return false;
        	}
        	st.pop();
        } else {
        	st.push(c);
        }
    }
	return !st.sz;
}
开发者ID:merkispavel,项目名称:lab5,代码行数:35,代码来源:task1.1.cpp

示例10: test_qa

void test_qa(AnsType& expectAns, OpreateType& opreateParam, InitType& initData, DataType1 firstData = DataType1()) {
    AnsType ans;
    MyStack work;

    for(int i=0; i<opreateParam.size(); i++) {
        int ansTmp = -1;
        if(opreateParam[i] == "push") {
            work.push(firstData[i]);
        }
        if(opreateParam[i] == "pop") {
            ansTmp = work.pop();
        }
        if(opreateParam[i] == "top") {
            ansTmp = work.top();
        }
        if(opreateParam[i] == "empty") {
            ansTmp = work.empty();
        }
        ans.push_back(ansTmp);
    }
    int index = getIndex();
    bool check = eq(ans, expectAns);
    if(!check) {
        printf("index %d: NO\n", index);
        output("opreateParam", opreateParam);
        output("initData", initData);
        output("firstData", firstData);
        output("ans", ans);
        output("expectAns", expectAns);

    } else {
        printf("index %d: YES\n", index);
    }
    printf("\n");
}
开发者ID:tiankonguse,项目名称:leetcode-solutions,代码行数:35,代码来源:implement-stack-using-queues.cpp

示例11: reset

void Graph<Tv, Te>::bcc(int s){ 
    reset(); int clock = 0; int v = s; MyStack<int> S;  //栈s用以记录已访问的顶点
    do{
        if(UNDISCOVERED == status(v) ){  //一旦发现未发现的顶点(新连通分量)
            BCC(v, clock, S);  //即从该顶点触发启动一次BCC
            S.pop(); //遍历返回后,弹出栈中最后一个顶点---当前连通域的起点
        }
    }while( s != (v = ( ++v % n)));
}
开发者ID:JarrettW,项目名称:DataStructure,代码行数:9,代码来源:GraphMatrix.cpp

示例12: main

int main()
{
	MyStack<int> stack;
	for(int i=0;i<10;i++)
		stack.Push(i);
	for(i=0;i<10;i++)
		cout<<stack.Pop()<<endl;
	return 0;
}
开发者ID:DodoXxRow,项目名称:Practice,代码行数:9,代码来源:coding2016_5_18_02.cpp

示例13: main

int main (void) 
{
	MyStack *pStack = new MyStack(5);
	pStack->push('a');
	pStack->push('e');
	pStack->push('i');
	pStack->push('o');
	pStack->push('u');
	//pStack->clearStack();
	
	pStack->stackTraverse(true);
	char elem = 0;
	pStack->pop(elem);
	cout << elem << endl;
	pStack->stackTraverse(true);
	cout << pStack -> stackLength() << endl;
	if(pStack->stackEmpty()){
		cout << "栈为空" << endl;
	}
	if(pStack->stackFull()){
		cout << "栈为满" << endl;
	}
	delete pStack;
	pStack = NULL;
	return 0;
}
开发者ID:syjs10,项目名称:c,代码行数:26,代码来源:demo.cpp

示例14: sortStack1

// 追加スタック数1
MyStack sortStack1(MyStack stack) {
    MyStack ans(10);
    while(!stack.isEmpty()) {
        int t = stack.peek(); stack.pop();
        /// 要素がansのtopより小さい間,ansからstackに戻す
        while (!ans.isEmpty() && ans.peek() < t) {
            stack.push(ans.peek());
            ans.pop();
        }
        ans.push(t);
    }

    return ans;
}
开发者ID:keigo-brook,项目名称:BookSutras,代码行数:15,代码来源:q5_sort_stack.cpp

示例15: twoNumsProcess

/* Function: twoNumsProcess()
 * Usage: is called by sortTokenByStacks() or getFinalStacksResult() functions
 * -----------------------------------------------------------------------------------------//
 * Makes single calculation for two top numbers in stack, and return result to
 * stackNumbers back.
 *
 *
 * @param stackNumbers      Stack of number values for current recursion
 * @param stackOperators    Stack of operators for current recursion */
void twoNumsProcess(MyStack<double> &stackNumbers, MyStack<string> &stackOperators) {
    /* Stacks elements validation checking for calculating process */
    if((stackNumbers.size() - stackOperators.size()) != 1) {
        cout << "   - CHECK YOUR INPUT, NOT ENOUGH NUMBERS IN FORMULA!" << endl;
        failFlag = true;
    } else {
        /* Calculating process */
        double num2 = stackNumbers.pop();
        double num1 = stackNumbers.pop();
        string thisOper = stackOperators.pop();
        double result = singleCalculation(num1, thisOper, num2);
        stackNumbers.push(result);
    }
}
开发者ID:ekuryatenko,项目名称:cs-b-assignment3_Calculator,代码行数:23,代码来源:Calculator.cpp


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