自己寫的一個入棧程序

#include <iostream>
using namespace std;

typedef struct student
{
	int data;
	struct student* next;
}node;


typedef struct stackqueue
{
	node *di,*top;
}queue;

queue *pushQ(queue *q,int data){
	node *n=(node*)malloc(sizeof(node));//缺了*
	n->data=data;
	n->next=NULL;
	if (q->di==NULL)//注意這個不是*q->di
	{
		q->di=n;
		q->top=n;
	}
	else{
		q->top->next=n;
		q->top=n;
	}
	return q;

}


 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章