summaryrefslogtreecommitdiff
path: root/c/dataStructure/栈和队列/队列/链队列/queue.c
diff options
context:
space:
mode:
Diffstat (limited to 'c/dataStructure/栈和队列/队列/链队列/queue.c')
-rwxr-xr-xc/dataStructure/栈和队列/队列/链队列/queue.c75
1 files changed, 75 insertions, 0 deletions
diff --git a/c/dataStructure/栈和队列/队列/链队列/queue.c b/c/dataStructure/栈和队列/队列/链队列/queue.c
new file mode 100755
index 0000000..94361d1
--- /dev/null
+++ b/c/dataStructure/栈和队列/队列/链队列/queue.c
@@ -0,0 +1,75 @@
+#include "queue.h"
+
+void InitQueue(pqueue * q)
+{
+ *q = NULL;
+}
+
+bool EmptyQueue(pqueue * qhead)
+{
+ if (!*qhead)
+ return true;
+ return false;
+}
+
+bool EnQueue(pqueue * qtail, ElemType * e)
+{
+ pqueue new = (pqueue) malloc (sizeof(Queue));
+ if (!new)
+ return false;
+ new->data = *e;
+ new->next = NULL;
+
+ if (!*qtail)
+ *qtail = new;
+ else
+ {
+ (*qtail)->next = new;
+ *qtail = new;
+ }
+
+ return true;
+}
+
+bool DeQueue(pqueue * qhead, ElemType * e)
+{
+ pqueue tmp = *qhead;
+ if (!*qhead)
+ return false;
+ *e = tmp->data;
+ *qhead = (*qhead)->next;
+ free(tmp);
+
+ return true;
+}
+
+bool RsQueue (pqueue * qhead)
+{
+ if (EmptyQueue(qhead))
+ return false;
+ pqueue tmp = *qhead;
+
+ while (!*qhead)
+ {
+ tmp = (*qhead)->next;
+ free(*qhead);
+ *qhead = tmp;
+ }
+
+ return true;
+}
+
+bool PrintQueue (pqueue * qhead)
+{
+ if (EmptyQueue(qhead))
+ return false;
+ pqueue tmp = *qhead;
+
+ while (tmp)
+ {
+ printf("%c", tmp->data);
+ tmp = tmp->next;
+ }
+ putchar('\n');
+ return true;
+}