本文整理汇总了C++中LinkedStack类的典型用法代码示例。如果您正苦于以下问题:C++ LinkedStack类的具体用法?C++ LinkedStack怎么用?C++ LinkedStack使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了LinkedStack类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: printHistory
void printHistory(LinkedStack<LinkedStack<Point> >& history, ostream& os = cout) {
if (!history.empty()) {
Point x = history.pop().peek();
printHistory(history);
os << x << endl;
}
}
示例2: printPath
void printPath(LinkedStack<Point>& path, ostream& os = cout) {
if (!path.empty()) {
Point x = path.pop();
printPath(path, os);
os << x << endl;
}
}
示例3: isBalanced
bool isBalanced(string brackets) //O(N)
{
LinkedStack bal = LinkedStack();
int c1=0, c2=0, c3=0;
string check;
for(int i=0; i< brackets.size(); i++)
{
bal.push(brackets.substr(i,1));
}
for(int j=0; j<brackets.size(); j++)
{
check=bal.pop();
if(check=="(") --c1;
else if(check==")") ++c1;
else if(check=="{") --c2;
else if(check=="}") ++c2;
else if(check=="[") --c3;
else if(check=="]") ++c3;
if(c1<0||c2<0||c3<0) return false;
}
//cout<<"c1: "<<c1<<" c2: "<<c2<<" c3: "<<c3<<endl;
return (c1==0&&c2==0&&c3==0);
}
示例4: horse_rec
bool horse_rec(Point start, Point end,
LinkedStack<Point>& path) {
if (start == end) {
path.push(end);
cout << "Успех!" << endl;
printPath(path);
return true;
}
if (board[start.first][start.second])
return false;
board[start.first][start.second] = true;
path.push(start);
// !!! cout << start << endl;
for(int dx = -2; dx <= 2; dx++)
if (dx != 0)
for(int sign = -1; sign <= 1; sign += 2) {
int dy = sign * (3 - abs(dx));
Point newstart(start.first + dx,
start.second + dy);
if (inside_board(newstart) &&
horse_rec(newstart, end, path))
return true;
}
path.pop();
return false;
}
示例5: Railroad
bool Railroad(int inputOrder[], int numberOfCars, int numberOfTracks) {
LinkedStack *holdingTracks = (LinkedStack *)malloc(numberOfTracks*sizeof(LinkedStack));
for (int i=0; i < numberOfTracks; i++) {
holdingTracks[i] = LinkedStack();
}
LinkedStack *outputTrack = new LinkedStack();
ostringstream railroadMoves; // stores the "moves" of each railroad car permutation
int nextCar = 1;
int index = numberOfCars - 1;
int currentCar = inputOrder[index];
while (nextCar <= numberOfCars) {
if (index >= 0) {
currentCar = inputOrder[index];
// send car straight to output
if (currentCar == nextCar) {
outputTrack->push(currentCar);
railroadMoves << "Move car " << currentCar << " from input to output" << endl;
nextCar++;
index--;
// try to output from holding tracks
if (outputFromHoldTrack(numberOfTracks, nextCar, outputTrack, holdingTracks, railroadMoves)) {
nextCar++;
}
}
else {
// if car cannot be sent straight to ouptut, put car in holding track
if (putInHold(currentCar, numberOfTracks, holdingTracks, railroadMoves)) {
index--;
}
// output from holding tracks
else if (outputFromHoldTrack(numberOfTracks, nextCar, outputTrack, holdingTracks, railroadMoves)) {
nextCar++;
}
// if none of the above work, return error
else {
cout << "permutation ";
for (int i=0; i< numberOfCars; i++) {
cout << inputOrder[i];
}
cout << " not feasible" << endl;
return false;
}
}
}
else {
// try to output from holding tracks
if (outputFromHoldTrack(numberOfTracks, nextCar, outputTrack, holdingTracks, railroadMoves)) {
nextCar++;
}
}
}
cout << railroadMoves.str(); // print moves if permutation is feasible
return true;
}
示例6: testPointStack
void testPointStack() {
LinkedStack<Point2D<int> > s;
s.push(Point2D<int>(1, 2));
s.push(Point2D<int>(2, 3));
s.push(Point2D<int>(3, 4));
while (!s.empty())
cout << s.pop();
}
示例7: testStackTemplate
void testStackTemplate() {
LinkedStack<double> ls;
ls.push(1.8);
cout << ls.pop() << endl;
LinkedStack<Point2D<double> > sp;
Point2D<double> p(1,2);
sp.push(p);
}
示例8: 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;
}
示例9: testCopy
void testCopy() {
LinkedStack<int> s;
for(int i = 1; i <= 10; i++)
s.push(i);
LinkedStack<int> s2 = s + 11 + 12;
LinkedStack<int> s3 = s;
s3 = 15 + s2;
printStack(s);
printStack(s2);
printStack(s3);
}
示例10: testStackStack
void testStackStack() {
LinkedStack<LinkedStack<Rational> > ss;
for(int i = 1; i <= 10; i++) {
LinkedStack<Rational> s;
for(int j = 1; j <= 10; j++) {
Rational r(i * j, (i+1)*(j+1));
s.push(r);
}
ss.push(s);
}
cerr << ss;
}
示例11: main
int main()
{ LinkedStack<int> numbers;
try
{ for (int i=10; i < 100; i+=10) numbers.push(i);
while (!numbers.isEmpty()) cout << numbers.pop() << endl;
numbers.pop();
}
catch(StackEmptyException e)
{ cerr << e;
return 1;
}
return 0;
}
示例12: make_sum_bigger
void make_sum_bigger(int n, int m, LinkedStack<int>& x, LinkedStack<int>& y, LinkedStack<int>& z){
int data_f = 0;
for(int i=0;i<m ;i++){ //Събира двета числа до позицията на по-малко
data_f += x.pop() + y.pop(); //
if(data_f < 10){
z.push(data_f);
data_f = 0; }
else {
z.push(data_f%10);
data_f = 1;
}
}
int result = data_f; // и прехвърля останалите цифри (+1 ако има едно на ум) от по-голямото число в стека с резултата
while(!x.empty()){
result += x.pop();
if (result >= 10){
z.push(result % 10);
result = 1;
}
else {
z.push(result);
result = 0;
}
}
}
示例13: sendSolution
void sendSolution() {
file << "Process 0 : Sending Solutions\n";
LinkedStack<Kostra> tempStack;
tempStack.add(solution);
solution->toString();
Transfer * t = new Transfer(&tempStack);
for (int i = 0; i < worldSize; i++) {
//neposilej zpravu sam sobe
if (i == rank) continue;
MPI_Send(t->transfer, t->size, MPI_SHORT, i, SOLUTION_TRANSMIT, MPI_COMM_WORLD);
}
t->print();
delete t;
}
示例14: make_sum_small
void make_sum_small(int n, int m, LinkedStack<int>& x, LinkedStack<int>& y, LinkedStack<int>& z){
//81094: Confusing bracket alignment within this function.
int data = 0;
for(int i=0;i<n;i++){
data += x.pop() + y.pop();
if(data < 10){
z.push(data);
data = 0; }
else {
z.push(data%10);
data = 1;
}
} int result = data;
while(!y.empty()){
result += y.pop();
if (result >= 10){
z.push(result % 10);
result = 1;
}
else {
z.push(result);
result = 0;
}
}
}
示例15:
void LinkedStack<T>::copy(LinkedStack<T> const& ls) {
/* !!! неправилно !!!
top = NULL;
while(!ls.empty())
push(ls.pop());
*/
if (ls.empty())
top = NULL;
else {
// първа стъпка
top = new StackElement<T>;
top->data = ls.top->data;
// подготовка за втората стъпка
StackElement<T>* toCopy = ls.top->next;
StackElement<T>* lastCopy = top;
while (toCopy != NULL) {
// копиране
StackElement<T>* newCopy = new StackElement<T>;
newCopy->data = toCopy->data;
// завързване
lastCopy->next = newCopy;
// подготовка за следващата стъпка
toCopy = toCopy->next;
lastCopy = newCopy;
}
// затваряме веригата
lastCopy->next = NULL;
}
}