title: C programming queue without using pointer
body: <p>Hi everyone i am new to this site..
  my question as below</p>
  
  <p>Queues are commonly used in network systems. For example, e-mail is placed
  in queues while it is waiting to be sent and after it arrives at the recipient’s
  mailbox. A problem occurs, however, if the outgoing mail processor cannot
  send one or more of the messages in the queue. For example, a message might
  not be sent because the recipient’s system is not available.
  Write an e-mail simulator that processes mail at an average of 40 messages
  per minute. As messages are received, they are placed in a queue.
  For the simulation assume that the messages arrive at an average rate of
  30 messages per minute. Remember, the messages must arrive randomly,
  so you need to use a random-number generator to determine when messages
  are received (see “Queue Simulation,” starting on page 175).
  Each minute, you can dequeue up to 40 messages and send them.
  Assume that 25% of the messages in the queue cannot be sent in any processing
  cycle. Again, you need to use a random number to determine
  whether a given message can be sent. If it can’t be sent, put it back at the
  end of the queue (enqueue it).
  Run the simulation for 24 hours, tracking the number of times each
  message had to be requeued. At the end of the simulation, print the statistics
  that show:
  a. The total messages processed
  b. The average arrival rate
  c. The average number of messages sent per minute
  d. The average number of messages in the queue in a minute
  e. The number of messages sent on the first attempt, the number sent on
  the second attempt, and so forth
  f. The average number of times messages had to be requeued (do not
  include the messages sent the first time in this average)</p>
  
  <p>however, since my C basic is weak, i create my own algorithm which i think i mayb manage to do it... and here is my algorithm</p>
  
  <p>//my own algorithm to do this question</p>
  
  <ol>
  <li>declare 40 elements (use as mail) sample : 40 mails in waiting list to be send (queue it)</li>
  <li>output like"mail[1] has been sent"
  1.random generate whether a mail success send or nt
  2.( using randomnum%4, if remainder =0,1,2 success , else fail)</li>
  <li>if fail, requeue the mails</li>
  <li>statistic 
  1.run the program once , get all the data like (msg sent in time then * 24) 
  2.get the time for all msg to be successfully sent and then get the statistic for 24 hours
  2.output the data on screen</li>
  </ol>
  
  <p>data
  -(msg sent in time then * 24 to get 24 hours data)
  -number of msg sent in 24 hours, change per minutes</p>
  
  <p>here is my work now
  //my code</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;time.h&gt;
  #include &lt;math.h&gt;
  #define MAX 500
  
  int queue_array[MAX];
  int rear=-1;
  int front=-1;
  void insert(int add_item);
  void delet(int add_item);
  void display();
  
  int main()
  {
      int element[40],i,j;
      srand(time(NULL));
      for (i=0;i&lt;40;i++)
      {       
          element[i]=rand();
          insert(element[i]);
          j=element[i]%4;
          if (j==3)
          {
          printf(" Mail failed to send. \n");
          delet(element[i]);
          insert(element[i]);
          }
          else
          printf(" Mail success to send.\n",j);
          delet(element[i]);
      }
      display();
      return 0;
  }
  
  void insert(int add_item)
  {
      if(rear==MAX-1)
      {
      printf("Queue Overflow \n");
      }
      rear=rear+1;
  }
  
  void delet(int)
  {
      if (front==-1 || front&gt;rear)
      {
          printf(" There is no mail in queue now. \n");
          return;
      }
      else
      {
          front=front+1;
      }
  }
  
  void display()
  {
      int i;
      if(front==-1)
      {
      printf(" All the email in queue have been sent.\n");
      }
      else
      {
          printf("Queue is : \n");
          for (i=front;i&lt;=rear;i++)
          printf("%d",queue_array[i]);
          printf("\n");
      }
  }
  </code></pre>