C语言数据结构队列实现-链表队列
简单实现了下链表队列代码如下
#include<stdio.h>
#include<stdlib.h>
typedef struct Node {
int data;
struct Node * next;
} Node;
//入队列
void insertList(Node * head, int elem){
Node * temp = head;
Node * newNode = (Node *)malloc(sizeof(Node));
newNode->data = elem;
newNode->next = NULL;
while(temp->next != NULL){
temp = temp->next;
}
temp->next = newNode;
}
//出队列
void pushlist(Node * head){
Node * temp = head->next;
printf("%d\n",temp->data);
head->next = temp->next;
}
//打印队列
void listprint(Node * head){
Node * tempBody=head->next;
while(tempBody){
printf("%d\n",tempBody->data);
tempBody = tempBody->next;
}
}
int main(){
Node * head = (Node *)malloc(sizeof(Node));
head->next = NULL;
insertList(head,10);
insertList(head,23);
insertList(head,56);
insertList(head,57);
insertList(head,59);
insertList(head,90);
insertList(head,87);
pushlist(head);
pushlist(head);
pushlist(head);
}