c語言之鏈表(單鏈表)

來源:互聯網
上載者:User

學會c語言,如果不知道鏈表或者不知道鏈表應在那裡,那就說明你的c語言還沒有學好,學好鏈表,知道應用在那裡,那說明你的c語言基礎性的東西基本掌握了。

/************************LinkCreare.c*********************/

#include "LinkApi.h"
#include <stdio.h>
#include <stdlib.h>

int main()
{
    stud *p;
    p=CreateNode(6);
         DisPlayNode(p);
    getchar();
    return 0;
}

 

/*************************LinkApi.c***********************/

#include "LinkApi.h"

stud * CreateNode(int n)
{
    int i;
    stud *head,*p1,*p2;
    head=p1=p2=NULL;

    for(i=0;i<n;i++)
    {
        p1=(stud *)malloc(sizeof(stud));
        p1->num=i;
        if(i==0)
        {
            head=p1;
        }
        else
        {
            p2->next=p1;   
        }   
        p2=p1;
    }
    p2->next=NULL;
    return head;   
}

void DisPlayNode(stud *p)
{
    while(p!=NULL)
    {
        printf("the %d node num is %d\n",p->num,p->num);
        p=p->next;   
    }
};

void DelNode(stud *p)
{
};

void FindNode(int num)
{
};

/*************************LinkApi.h***********************/

#ifndef         LINKAPI_H
#define       LINKAPI_H

#include "malloc.h"
#include "stdio.h"
#include "stdlib.h"

typedef struct node{
    int num;
    struct node *next;
}stud;

stud * CreateNode(int n);
void DisPlayNode(stud *p);
void DelNode(stud *p);
void FindNode(int num);

#endif

/*******************makefile*****************************/

# This is a Link for simple without circle
CFLAGS = -g -Wall
CC          = gcc

OBJECTS = LinkCreate.o LinkApi.o

Link : ${OBJECTS}
        ${CC} ${CFLAGS}  -o Link ${OBJECTS}
LinkApi.o : LinkApi.c
      ${CC} ${CFLAGS} -c  LinkApi.c
LinkCreate.o : LinkCreate.c
      ${CC} ${CFLAGS} -c  LinkCreate.c
clean :
    rm -rf *.o Link

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.