C 언어: [단일 체인 테이블] 역방향 반전 단일 체인 테이블

#include<stdio.h>
#include<assert.h>
#include<stdlib.h>

typedef int DataType;

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

SListNode* BuyNode(DataType x)
{
    SListNode* next = (SListNode*)malloc(sizeof(SListNode));
    next->data = x;
    next->next = NULL;
    return next;
}

void PushBack(SListNode* & ppHead, DataType x)
{
    if (ppHead == NULL)
    {
        ppHead = BuyNode(x);
    }
    else
    {
        SListNode* tail = ppHead;
        while (tail->next != NULL)
        {
            tail = tail->next;
        }
        tail->next = BuyNode(x);
    }
}

//       
void PushFront(SListNode* & ppHead,DataType x)
{
    SListNode* cur = BuyNode(x);
    cur->next = ppHead;
    ppHead = cur;
}

void PrintSNodeList(SListNode* ppHead)
{
    while (ppHead)
    {
        printf("%d->", ppHead->data);
        ppHead = ppHead->next;
    }
    printf("
"); } void Test3() {     SListNode* List = NULL;     PushFront(List, 1);     PushFront(List, 2);     PushFront(List, 3);     PushFront(List, 4);     PushFront(List, 5);     PrintSNodeList(List); } int main() {     Test3();     system("pause");     return 0; }

좋은 웹페이지 즐겨찾기