Basic ordered queue operations

Source: Internet
Author: User
`# Include "stdafx. H "# include" stdio. H "# include" stdlib. H "# define small 1 # If (small) # define Max 7 int queuedata [Max] = {'A', 'B', 'C', 'D ', 'E', 'F', 'G'}; # else # define max 14 int queuedata [Max] = {'A', 'B', 'C ', 'D', 'E', 'F', 'G', 'h', 'I', 'J', 'k', 'l', 'M ', 'N'}; # endif/* sequence queue type definition */typedef struct {int data [Max]; int head; int tail;} sqqueue; /* chain queue type definition */struct linkqueue {int data; struct linkqueue * link;}; typedef Str UCT linkqueue lkqueue; // define/* basic operation function definition of ordered queue * // initialization function of ordered queue sqinitialize () sqqueue * sq_initialize () {sqqueue * P; P = (sqqueue *) malloc (sizeof (sqqueue); If (P = NULL) {return (null);} else {P-> data [0] = 0; p-> head = 0; P-> tail = 0; Return (p) ;}/// empty judge function of the ordered queue qisempty () int qisempty (sqqueue * Queue) {If (queue-> head = queue-> Tail) Return (1); else return (0);} // The qisfull () int qisfull (sqqueue * Queue) function of the ordered queue) {If (queue-> head = max) Return (1); else return (0);} // The queuing function qinqueue () int qinqueue (sqqueue * queue, int data) {If (queue-> tail = max) {printf ("the queue is full! /N "); Return (0);} else {queue-> data [queue-> tail ++] = data; Return (1 );}} // The queuing function qoutqueue () int qoutqueue (sqqueue * queue, int * P) {If (queue-> head = queue-> tail) {printf ("the queue is empty! /N "); Return (0);} else {* P = queue-> data [queue-> head ++]; Return (1 );}} // The qinputvalue () void qinputvalue (sqqueue * queue, int array []) {int I = 0; while (qinqueue (queue, array [I]) printf ("queue [% d] = % C/T", I, array [I ++]);} // qoutputvalue () void qoutputvalue (sqqueue * Queue) {int I, queuedata; I = 0; while (qoutqueue (queue, & queuedata )) printf ("queue [% d] = % C/T", I ++, queuedata); printf ("/n ");} // Define/* Definition of basic operation functions of chained queue * // The initialization function lk_initialize () lkqueue * lk_initialize () {lkqueue * P; P = (lkqueue *) malloc (sizeof (lkqueue); If (P = NULL) {return (null);} else {P-> DATA = 0; p-> link = NULL; Return (p) ;}// the queuing function lkinqueue () of the chained queue // Note: When you enter the queue, the parameter is the team-end pointer, the returned value is also the team end pointer lkqueue * lkinqueue (lkqueue * tail, int data) {lkqueue * P; P = (lkqueue *) malloc (sizeof (lkqueue); If (P = NULL) {printf ("memory overflow when chained queue elements are added! /N "); Return (tail) ;}else {P-> DATA = data; P-> link = tail; Return (p );}} // chain queue's dispatch function lkinqueue () // Note: When a queue is exited, the parameter is the first pointer of the queue, and the returned value is also the first pointer of the queue lkqueue * lkoutqueue (lkqueue * head, int * Data) {* P = head-> data; lkqueue * P; P = (lkqueue *) malloc (sizeof (lkqueue); If (P = NULL) {printf ("memory overflow when creating a chain queue! /N "); Return (tail) ;}else {P-> DATA = data; P-> link = tail; Return (p );}} // optional int main (INT argc, char * argv []) {sqqueue * queue1; lkqueue ** lkhead, ** lktail; queue1 = sq_initialize (); if (queue1 = NULL) {printf ("memory overflow when creating an ordered queue! /N "); Return 0;} else {printf ("/n ordered queue [queue] data ......... /n "); qinputvalue (queue1, queuedata); printf ("/n sequential queue [queue] data ......... /n "); qoutputvalue (queue1);} printf ("/n finished! /N "); Return 0 ;}`
Related Keywords:

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.