Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. //---------------------------------------------------------------------------
  2.  
  3. #include <vcl.h>
  4. #pragma hdrstop
  5. #include <iostream.h>
  6. //---------------------------------------------------------------------------
  7.  
  8. #pragma argsused
  9. #include <iostream>
  10. #include <vcl>
  11. #include <iostream>
  12. #include <time.h>
  13. using namespace std;
  14.  
  15. struct stek{
  16. int num;
  17. stek *next;
  18. };
  19.  
  20. void push(stek* &stk, int n){
  21. stek *temp = new stek;
  22. temp->next = stk;
  23. temp->num = n;
  24. stk = temp;
  25. }
  26.  
  27. void show(stek *stk){
  28. stek *temp = stk;
  29. while(temp){
  30. cout<<temp->num<<" ";
  31. temp = temp->next;
  32. }
  33. cout<<endl;
  34. }
  35.  
  36. int findAverage(stek *stk){
  37. int amount = 0, i = 0;
  38. for(stek *temp = stk; temp ; temp = temp->next, i++)
  39. amount += temp->num;
  40. return amount/i;
  41. }
  42.  
  43. void cleanOut(stek* &stk){
  44. for(stek *temp = stk->next;stk->next;temp = stk->next){
  45. delete stk;
  46. stk = temp;
  47. }
  48. }
  49.  
  50. int main(){
  51. stek *stk = new stek;
  52. stk = NULL;
  53. srand(time(NULL));
  54. for(int i=0;i<10;i++)
  55. push(stk, rand()%100);
  56. show(stk);
  57. stk->num = findAverage(stk);
  58. show(stk);
  59. system("pause > nul");
  60. cleanOut(stk); // Î÷èùàåì ñòåê
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement