代码改变世界

第八周 技术博客发表 数据结构

2016-04-28 21:10  you123  阅读(149)  评论(0编辑  收藏  举报

#include "stdafx.h"

#include "stdio.h"
#include "stdlib.h"

typedef int DataType;

typedef struct Space
{
 DataType data;
 Space* next;
}Space;

typedef struct Queue
{
 Space* base;
 Space* top;
 int length;
 
}Queue;

Queue* initQ()
{
 Queue *myQ;
 myQ=(Queue *)malloc(sizeof(Queue));
 myQ->length;
 myQ->base=(Space *)malloc(sizeof(Space));
 myQ->base->next=NULL;
 myQ->top=myQ->base;
 return myQ;
}

void insQ(Queue* myQ, DataType data)
{
 Space *temp=(Space *)malloc(sizeof(Space));
 temp->next=NULL;
 temp->data=data;
 myQ->top->next=temp;
 myQ->top->next=myQ->top->next->next;
 myQ->length++;
}

void remQ(Queue* myQ)
{
 if(myQ->length==0)
  printf("the queue is empty");
 Space* temp=myQ->base->next;
 myQ->base->next=myQ->base->next->next;
 free(temp);
 myQ->length--;
}

void getTop(Queue* myQ)
{
 printf("%d  \n",myQ->base->next->data );
}

 

int main(int argc, char const *argv[])
{
 /* code */
 return 0;
}