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


C++ LinkedStack::Add方法代码示例

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


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

示例1: CheckBox

bool CheckBox(int p[],int n)
{
	LinkedStack<int> s;
	int c;
	for(int i=0;i<n;i++)
	{
		if(!s.IsEmpty())
		{
			if(s.Top()==p[i])
				s.Delete(c);
			else
				s.Add(p[i]);
			
		}
		else
		{
			s.Add(p[i]);
		}
	}
	if(s.IsEmpty())
		return true;
	else 
		return false;

}
开发者ID:ETAF90,项目名称:codeStorage,代码行数:25,代码来源:ch5-开关盒布线.cpp

示例2: main

int main() {
	int x;
	LinkedStack<int> L;
	L.Add(2).Add(1).Add(8);
	cout << " Top element is " << L.Top() << endl;
	L.Delete(x);
	cout << " Element deleted is " << x << endl;
	cout << " Top element is " << L.Top() << endl;
	system("pause");
	return 0;
}
开发者ID:PeterWang9,项目名称:code,代码行数:11,代码来源:LinkedStack.cpp

示例3: main

void main(void)
{// Offline equivalenece classes.
   int n, r;

   // input n and r
   cout << "Enter number of elements" << endl;
   cin >> n;
   if (n < 2) {cerr << "Too few elements" << endl;
               exit(1);}
   cout << "Enter number of relations" << endl;
   cin >> r;
   if (r < 1) {cerr << "Too few relations" << endl;
               exit(1);}

   // create an array of n chains
   Chain<int> *chain;
   try {chain = new Chain<int> [n+1];}
   catch (NoMem) {cerr << "Out of memory" << endl;
                  exit(1);}
              
   // input the r relations and put on chains
   for (int i = 1; i <= r; i++) {
      cout << "Enter next relation/pair" << endl;
      int a, b;
      cin >> a >> b;
      chain[a].Insert(0,b);
      chain[b].Insert(0,a);
      }
   
   // initialize to output classes
   LinkedStack<int> stack;
   bool *out;
   try {out = new bool [n+1];}
   catch (NoMem) {cerr << "Out of memory" << endl;
                  exit(1);}
   for (int i = 1; i <= n; i++)
      out[i] = false;
   
   // output classes
   for (int i = 1; i <= n; i++)
     if (!out[i]) {// start of a new class
        cout << "Next class is: " << i << ' ';
        out[i] = true;
        stack.Add(i);
        // get rest of class from stack
        while (!stack.IsEmpty()) {
           int *q, j;
           stack.Delete(j);

           // elements on chain[j] are in
           // same class, use iterator c
           // to get them
           ChainIterator<int> c;
           q = c.Initialize(chain[j]);
           while (q) {// q is in same class
              if (!out[*q]) {
                    cout << *q << ' ';
                    out[*q] = true;
                    stack.Add(*q);}
              q = c.Next();
              }
           }
        cout << endl;
        }

   cout << endl << "End of class list" << endl;
}  
开发者ID:hzsunzixiang,项目名称:programming,代码行数:67,代码来源:equiv.cpp


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