Quantcast
Channel: CodeGuru Forums - Visual C++ Programming
Viewing all articles
Browse latest Browse all 3042

Create a new stack in which to put every third element of the first stack

$
0
0
Hello! I need some help. I have to do the following task: Create a stack with numbers in the range from -50 to +50. After creating the stack, perform the following actions: create a new stack, in which every third element of the first stack will be placed. Upon completion, all stacks must be removed. I was able to write the code of the program with creating a stack in the specified range, viewing and deleting it, but I can not implement the function to create the second stack. Code: --------- #include "stdafx.h" #include #include #include #include using namespace std; struct Stack { int info; int in; Stack *next; } *begin1, *second; Stack* InStack(Stack*, int); void View(Stack*); Stack* DelStackAll(Stack*); int main() { srand(time(0)); int i; for(i=1; i<=10; i++) { begin1=InStack(begin1, rand()%101-50); } View(begin1); begin1=DelStackAll(begin1); getchar(); } Stack* InStack(Stack *p, int in){ Stack *t=new Stack; t->info=in; t->next=p; return t; } void View(Stack *p) { Stack *t=p; while (t!=NULL) { cout<info; t=t->next; } cout<next; delete t; } return p; } --------- I will be very grateful for the help!

Viewing all articles
Browse latest Browse all 3042

Trending Articles