Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <time.h>
- struct Queue{
- char message[256];
- struct Queue* next;
- };
- void enquene(struct Queue** _emails, char message[256]){
- //initilize the new email to be added
- struct Queue* toAdd;
- toAdd = (struct Queue*) malloc (sizeof(struct Queue));
- toAdd->message = message;
- toAdd->next=NULL;
- //if list is empty add it at the front
- if(*_emails == NULL){
- *_emails = toAdd;
- return;
- }
- //navigate to the end of the list
- struct Queue* current;
- for (current = *_emails;current->next!=NULL;current = current->next);
- //add the new email to the queue
- current->next = toAdd;
- }
- //deletes on element of off the front of the queue and returns it
- struct Queue* dequeue (struct Queue** _emails){
- if (**_emails == NULL)
- return _emails;
- struct Node* current = *_emails;
- *_emails = (*_emails)->next;
- return current;
- //free?
- }
- int main(){
- //used for random integers
- srand(time(NULL));
- int randNum;
- struct Queue *emails;
- emails = (struct Queue*) malloc (sizeof(struct Queue));
- while(true){
- //enquene every iterations which is 40 iterations a minute so 40 messages a minute
- enquene(emails, "message");
- //randNum is a number between 1 and 100
- randNum = 1+(rand()%100);
- //if it is not one of the 25%
- if (randNum >25){
- dequene(emails);
- }
- //otherwise move it to the back
- else{
- enquene(emails, dequene(emails)->message);
- }
- //slows it down to do 40 iterations in a minute
- delay(1500);
- }
- }
Add Comment
Please, Sign In to add comment