Guest User

Untitled

a guest
Dec 7th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include "Queue.h"
  3.  
  4.  
  5. int _tmain(int argc, _TCHAR* argv[])
  6. { Queue q;
  7. q.push(4);
  8. q.push(3);
  9. q.push(2);
  10. q.push(1);
  11. q.ausgebenQueue();
  12. printf("\n");
  13. printf("es wurde die Zahl %d geloescht\n",q.pop());
  14. printf("es wurde die Zahl %d geloescht\n",q.pop());
  15. printf("In der Queue befinden sich nun die Zahlen ");
  16. q.ausgebenQueue();
  17. getch();
  18. return 0;
  19. }
  20.  
  21. #include"Queue.h"
  22. #include "stdafx.h"
  23.  
  24. Queue::Queue()
  25. { this->daten=NULL;
  26. this->size=0;
  27. }
  28.  
  29. void Queue::push(int wert)
  30. { this->size++;
  31. int* help=(int*)malloc((this->size)*sizeof(int));
  32.  
  33. help[0]=wert;
  34. for(int i=1; i<this->size; i++)
  35. help[i]=this->daten[i-1];
  36. this->daten=(int*)realloc(this->daten,(this->size)*sizeof(int));
  37. for(int i=0; i<this->size;i++)
  38. this->daten[i]=help[i];
  39.  
  40. free(help);
  41. }
  42.  
  43. void Queue::ausgebenQueue()
  44. {
  45. for(int i=0; i<this->size; i++)
  46. printf("%d ",this->daten[i]);
  47. }
  48.  
  49. int Queue::pop()
  50. { int retwert=-1;
  51. int i=0;
  52. this->size--;
  53. int* help=(int*)malloc((this->size)*sizeof(int));
  54.  
  55. for(i=0; i<this->size; i++)
  56. help[i]=this->daten[i];
  57. retwert=this->daten[i];
  58. this->daten=(int*)realloc(this->daten,(this->size)*sizeof(int));
  59. for(int j=0; j<this->size; j++)
  60. this->daten[j]=help[j];
  61. return retwert;
  62.  
  63. }
Add Comment
Please, Sign In to add comment