我堆疊型別定義是
typedef struct stacknote
{
char data;
struct stacknote *next;
}stacknote,*Linkstackptr;
typedef struct node
{
int count;
Linkstackptr top;
}Linkstack;
在置空堆疊函式中的動態分配記憶體格式
void Initstack(Linkstack* s)
{
s = (Linkstack*)malloc(sizeof(Linkstack));
if (*s == NULL)
{
return;
}
else
{
s->top = NULL;
}
}
這是佇列的型別定義和動態分配記憶體格式
typedef struct queuenote
{
int data;
struct queuenote *next;
}queuenote,*Linkqueueptr;
typedef struct
{
Linkqueueptr front,rear;
}Linkqueue;
置空
int Initqueue(Linkqueue *p)
{
p->front=p->rear=(Linkqueueptr)malloc(sizeof(queuenote));
if(!p->front)
{
return 0;
}
p->front->next=p->rear->next=NULL;
return 1;
}
為什么這兩個不一樣 我在適應了堆疊的格式后,把他套在佇列上 結果不對這是為什么求大佬決議一下。
最后還有一個小問題
void print(Linkqueue q)
{
while(q.front!=q.rear)
{
q.front=q.front->next; //注意front指向頭結點非第一個結點 故先指向下一個
printf("%d\n",q.front->data);
}
}在列印佇列的時候為啥是q.front而不是q->front
這兩個有啥差別
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/14641.html
標籤:C語言
上一篇:尾插法建立單鏈表相關問題
下一篇:c語言 結構體變數的參考
