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