Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include "Queue.h"
- int _tmain(int argc, _TCHAR* argv[])
- { Queue q;
- q.push(4);
- q.push(3);
- q.push(2);
- q.push(1);
- q.ausgebenQueue();
- printf("\n");
- printf("es wurde die Zahl %d geloescht\n",q.pop());
- printf("es wurde die Zahl %d geloescht\n",q.pop());
- printf("In der Queue befinden sich nun die Zahlen ");
- q.ausgebenQueue();
- getch();
- return 0;
- }
- #include"Queue.h"
- #include "stdafx.h"
- Queue::Queue()
- { this->daten=NULL;
- this->size=0;
- }
- void Queue::push(int wert)
- { this->size++;
- int* help=(int*)malloc((this->size)*sizeof(int));
- help[0]=wert;
- for(int i=1; i<this->size; i++)
- help[i]=this->daten[i-1];
- this->daten=(int*)realloc(this->daten,(this->size)*sizeof(int));
- for(int i=0; i<this->size;i++)
- this->daten[i]=help[i];
- free(help);
- }
- void Queue::ausgebenQueue()
- {
- for(int i=0; i<this->size; i++)
- printf("%d ",this->daten[i]);
- }
- int Queue::pop()
- { int retwert=-1;
- int i=0;
- this->size--;
- int* help=(int*)malloc((this->size)*sizeof(int));
- for(i=0; i<this->size; i++)
- help[i]=this->daten[i];
- retwert=this->daten[i];
- this->daten=(int*)realloc(this->daten,(this->size)*sizeof(int));
- for(int j=0; j<this->size; j++)
- this->daten[j]=help[j];
- return retwert;
- }
Add Comment
Please, Sign In to add comment