[C]リスト構造
久しぶりにC言語復習。
リスト構造。
-- Stack.c --
#include "Stack.h"
#include "List.h"
static List *stList;
void InitList()
{
stList = (List*)malloc(sizeof(List));
}
int Pop()
{
int iReturnValue = stList->value;
Delete(stList);
return iReturnValue;
}
void Push(int iValue)
{
stList = Add(stList, iValue);
}
-- List.c --
#include <stdlib.h>
#include "List.h"
List* Add(List *pstNode, int iValue)
{
List* pstNewNode = (List*)malloc(sizeof(List));
pstNewNode->value = iValue;
pstNewNode->next = pstNode;
pstNode = pstNewNode;
return pstNode;
}
void Delete(List *pstNode)
{
List *pstDeleteNode = pstNode->next;
free(pstNode);
pstNode = pstDeleteNode;
}
-- List.h --
#pragma once
typedef struct LIST_TAG
{
int value;
struct LIST_TAG* next;
}List;
List* Add(List *pstNode, int iValue);
void Delete(List *pstNode);