Simulate average stay of bank customers

Source: Internet
Author: User


Stack exercises in data structure (c)

# Include <stdlib. h>
# Include <stdio. h>
# Include <malloc. h>
# Include <conio. h>
# Define ERROR 0
# Define OK 1
Typedef struct {
Int OccurTime;
Int NType;
} Event;
Typedef struct {
Int ArrivalTime;
Int Duration;
} QElemType;
Struct LNODE
{
Event data;
Struct LNODE * next;
};
Typedef struct LNODE LNode;
Typedef struct LNODE * LinkList;
Typedef struct LNODE * EvenList;
Typedef struct QNode {
QElemType elem;
Struct QNode * next;
} QNode, * QueuePtr;
Typedef struct
{QueuePtr front;
QueuePtr rear;
} LinkQueue;
EvenList ev;
Event en;
LinkQueue q [5];
QElemType customer;
Int TotalTime, CustomerNum, CloseTime;

Int InitList (EvenList * L)
{
* L = (LNode *) malloc (sizeof (LNode ));
If (! (* L) exit (ERROR );
(* L)-> next = NULL;
Return OK;
}
Int DelFirst (EvenList * L, Event * e)
{LNode * pc, * q;
Pc = * L; q = pc-> next;
Pc-> next = q-> next; * e = q-> data; return OK ;}
Int ListEmpty (LNode L)
{LNode * p;
Int j = 0;
P = L. next;
While (p)
{J ++; break ;}
If (j = 0) return 1;
Else return 0;
}
Int compare (Event a, Event B)
{If (a. OccurTime> B. OccurTime) return 1;
Else if (a. OccurTime = B. OccurTime) return 0;
Else return-1;
}
Int OrderInsert (EvenList * L, Event e, int (* cmp) (Event, Event ))
{LNode * p, * pc;/* Insert the event to the linked list */
P = (LNode *) malloc (sizeof (LNode);/* allocate space */
If (! P) {printf ("not"); return (0 );}
If (ListEmpty (** L ))
{P-> data = e; p-> next = (* L)-> next; (* L)-> next = p ;}
Else {
Switch (cmp (* L)-> next)-> data, e ))
{Case-1: pc = (* L)-> next;
While (pc-> next! = NULL)
{
If (pc-> next)-> data. OccurTime <= e. OccurTime)
Pc = pc-> next;
Else break;
}
P-> data = e; p-> next = pc-> next;/* connect it before it is bigger */
Pc-> next = p; break;
& Nbs

<

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.