Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- https://www.programiz.com/cpp-programming/stack
- https://www.programiz.com/cpp-programming/queue
- /* STACK
- push() adds an element into the stack
- pop() removes an element from the stack
- top() returns the element at the top of the stack
- size() returns the number of elements in the stack
- empty() returns true if the stack is empty
- */
- #include <iostream>
- #include <stack>
- using namespace std;
- ///////////////////////////////////////////////
- int main() //
- {
- stack<string> colors; // create a stack of strings
- colors.push("Red"); // push elements into the stack
- colors.push("Orange");
- cout << "Stack: ";
- while(colors.empty() != 1) // print elements of stack
- {
- cout << colors.top() << ", ";
- colors.pop();
- }
- return 0;
- }
- /* QUEUE
- push() inserts an element at the back of the queue
- pop() removes an element from the front of the queue
- front() returns the first element of the queue
- back() returns the last element of the queue
- size() returns the number of elements in the queue
- empty() returns true if the queue is empty
- */
- /*
- #include <iostream>
- #include <queue>
- using namespace std;
- //////////////////////////////////////////////////////
- int main() //
- {
- queue<string> animals; // create a queue of string
- animals.push("Cat"); // push elements into the queue
- animals.push("Dog");
- cout << "Queue: ";
- while(animals.empty() != 1 ) // print elements of queue
- { // loop until queue is empty
- cout << animals.front() << ", "; // print the element
- animals.pop(); // pop element from the queue
- }
- cout << endl;
- return 0;
- }
- */
- #include <stdio.h>
- #include <stdlib.h>
- int n = 7;
- int *p = (int*)malloc(4);
- /////////////////////////////////////////////////////////
- int main() //
- {
- int n = 55;
- int w = *p;
- int &a = *p = 22;
- int &a2 = a;
- printf("a = %d\n", a2);
- free(p);
- }
- /*
- #include <stdio.h>
- #include <stdlib.h>
- int n = 7;
- int *p = (int*)malloc(4);
- int *p1 = new(int);
- /////////////////////////////////////////////////////////
- int main() //
- {
- int n = 55;
- int w = *p;
- int &a = *p;
- printf("a = %d\n", a);
- free(p);
- delete(p1);
- }
- */
- /*
- #define _CRT_SECURE_NO_WARNINGS
- #include <stdio.h>
- /////////////////////////////////////////////////////////
- int main() //
- {
- int num_books,
- book_num = 1,
- price = 1000,
- Glav_ptice = 1000;
- printf("Enter the number of books purchased: "); scanf("%d", &num_books);
- for(int i = 0; i < num_books; i++)
- {
- printf("Book %d costs %d rubles\n", book_num, Glav_ptice);
- if(book_num % 7 == 0) price = 1000;
- else price -= 55;
- Glav_ptice += price;
- book_num ++;
- }
- return 0;
- }
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement