Linked List (single-chain table) in C Language)

Source: Internet
Author: User

Learn the C language. If you do not know the linked list or do not know where the linked list should be, it means that your C language has not learned well. Learn the linked list and know where the application is located, it means that you have mastered the basic things of C language.

/************************ 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.