Advertisement
dllbridge

Untitled

Apr 14th, 2023
832
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.50 KB | None | 0 0
  1. https://www.programiz.com/cpp-programming/stack
  2. https://www.programiz.com/cpp-programming/queue
  3.  
  4. /*  STACK
  5.     push()  adds an element into the stack
  6.     pop()   removes an element from the stack
  7.     top()   returns the element at the top of the stack
  8.     size()  returns the number of elements in the stack
  9.     empty() returns true if the stack is empty
  10. */
  11.  
  12. #include  <iostream>
  13. #include     <stack>
  14. using namespace std;
  15.  
  16.  
  17.  
  18. ///////////////////////////////////////////////
  19. int main()                                   //
  20. {
  21.  
  22.     stack<string> colors;                    // create a stack of strings
  23.  
  24.  
  25.     colors.push("Red");                      // push elements into the stack
  26.     colors.push("Orange");
  27.  
  28.     cout << "Stack: ";
  29.  
  30.  
  31.     while(colors.empty() != 1)               // print elements of stack
  32.     {
  33.        
  34.        cout << colors.top() << ", ";
  35.        colors.pop();
  36.     }
  37.  
  38. return 0;
  39. }
  40.  
  41.  
  42.  
  43. /*  QUEUE
  44.  
  45.     push()  inserts an element at the back of the queue
  46.     pop()   removes an element from the front of the queue
  47.     front() returns the first element of the queue
  48.     back()  returns the last element of the queue
  49.     size()  returns the number of elements in the queue
  50.     empty() returns true if the queue is empty
  51.  
  52. */
  53.  
  54. /*
  55. #include <iostream>
  56. #include    <queue>
  57. using namespace std;
  58.  
  59.  
  60. //////////////////////////////////////////////////////
  61. int main()                                          //  
  62. {
  63.  
  64.     queue<string> animals;                          // create a queue of string
  65.  
  66.     animals.push("Cat");                            // push elements into the queue
  67.     animals.push("Dog");
  68.  
  69.     cout << "Queue: ";
  70.  
  71.     while(animals.empty() != 1 )                    // print elements of queue
  72.     {                                               // loop until queue is empty
  73.  
  74.          cout << animals.front() << ", ";           // print the element
  75.  
  76.          animals.pop();                             // pop element from the queue
  77.     }
  78.  
  79.     cout << endl;
  80.  
  81. return 0;
  82. }
  83.  
  84. */
  85.  
  86.  
  87.  
  88. #include  <stdio.h>
  89. #include <stdlib.h>
  90.  
  91. int n = 7;
  92.  
  93.  
  94. int *p = (int*)malloc(4);
  95.  
  96.  
  97.  
  98.  
  99.  
  100. /////////////////////////////////////////////////////////
  101. int main()                                             //
  102. {
  103.  
  104.     int n = 55;
  105.    
  106.     int w = *p;
  107.    
  108.     int &a  = *p = 22;
  109.     int &a2 =  a;
  110.    
  111.     printf("a = %d\n", a2);
  112.    
  113.     free(p);
  114.    
  115.  
  116.  
  117. }
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131. /*
  132. #include  <stdio.h>
  133. #include <stdlib.h>
  134.  
  135. int n = 7;
  136.  
  137.  
  138. int *p = (int*)malloc(4);
  139.  
  140.  
  141. int *p1 = new(int);
  142.  
  143.  
  144. /////////////////////////////////////////////////////////
  145. int main()                                             //
  146. {
  147.  
  148.     int n = 55;
  149.    
  150.     int w = *p;
  151.    
  152.     int &a = *p;
  153.    
  154.     printf("a = %d\n", a);
  155.    
  156.     free(p);
  157.    
  158.     delete(p1);
  159.  
  160. }
  161. */
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185. /*
  186.  
  187.  
  188. #define _CRT_SECURE_NO_WARNINGS
  189. #include <stdio.h>
  190.  
  191.  
  192. /////////////////////////////////////////////////////////
  193. int main()                                             //
  194. {
  195.    
  196.     int  num_books,
  197.           book_num =    1,
  198.              price = 1000,
  199.         Glav_ptice = 1000;
  200.    
  201.     printf("Enter the number of books purchased: ");  scanf("%d", &num_books);
  202.  
  203.    
  204.     for(int i = 0; i < num_books; i++)
  205.     {
  206.         printf("Book %d costs %d rubles\n", book_num, Glav_ptice);
  207.  
  208.         if(book_num % 7 == 0) price = 1000;
  209.         else                  price -=  55;
  210.        
  211.         Glav_ptice += price;
  212.         book_num   ++;
  213.     }
  214.  
  215.     return 0;
  216. }
  217.  
  218. */
  219.  
  220.  
  221.  
  222.  
  223.  
  224.  
  225.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement