-4
我剛剛開始用C編程學校。我被要求做一個使用FIFO結構來解決數學問題的程序。我在互聯網上得到了一個FIFO的代碼,我只是不知道如何使用它。我嘗試了很多東西,在互聯網上找不到任何有用的東西,或許我只是不知道正確的研究方法,但是能否幫助我?謝謝!你如何爲FIFO使用typedef結構?
#include <stdio.h>
#include <stdlib.h>
typedef struct pile
{
int donnee;
struct pile *precedent;
} Pile;
void pile_push(Pile **p_pile, int donnee)
{
Pile *p_nouveau = malloc(sizeof *p_nouveau);
if (p_nouveau != NULL)
{
p_nouveau->donnee = donnee;
p_nouveau->precedent = *p_pile;
*p_pile = p_nouveau;
}
}
int pile_pop(Pile **p_pile)
{
int ret = -1;
if (p_pile != NULL)
{
Pile *temporaire = (*p_pile)->precedent;
ret = (*p_pile)->donnee;
free(*p_pile), *p_pile = NULL;
*p_pile = temporaire;
}
return ret;
}
void pile_clear(Pile **p_pile)
{
while (*p_pile != NULL)
{
pile_pop(p_pile);
}
}
我試着這樣做:
int main()
{
int return_val;
Pile pile;
pile_push(Pile, 5);
return_val = pile_pop(Pile);
printf(return_val);
}
,並得到這個錯誤:
expected expression before 'Pile'
too few arguments to function 'pile_push'
你的確切問題是什麼? –
如果你不明白代碼,你怎麼知道它甚至會做你想要的?從互聯網上獲取隨機代碼,你甚至不能開始理解可能不是一個好主意。最好從最初的原則中學習東西。無論如何,「用於fifo的typedef結構」並沒有多大意義。你認爲「fifo結構」究竟是什麼(不清楚你的意圖是什麼)? – kaylum
嘗試查找術語「隊列」;使用FIFO規則。還有堆棧(LIFO或'後進先出')和出隊隊列(雙端隊列),它們結合了堆棧和隊列功能。 –