• Welcome to the world's largest Chinese hacker forum

    Welcome to the world's largest Chinese hacker forum, our forum registration is open! You can now register for technical communication with us, this is a free and open to the world of the BBS, we founded the purpose for the study of network security, please don't release business of black/grey, or on the BBS posts, to seek help hacker if violations, we will permanently frozen your IP and account, thank you for your cooperation. Hacker attack and defense cracking or network Security

    business please click here: Creation Security  From CNHACKTEAM

Recommended Posts

单链表的定义

单链表是线性结构,每个结点都有一个数据域和指针域,用以指向后继结点,可以通过前驱结点中的指针域中的地址信息找到后继结点的位置,所以链表有一个缺点就是不能直接找到某个结点,而是要从头结点开始依次查找,即链表不支持随机访问。

结构体表示如下:

#include <iostream>
using namespace std;
typedef struct 
Node{
    int data;
    sruct Node* next;
}Node;
int main(){
   ...
    return 0;
}

单链表的基本操作

初始化

创建头结点保证头指针始终不为NULL,如果为空表则头结点的next指针为NULL

Node* InitList(){
    Node* headNode = (Node*)malloc(sizeof(Node));
    Node -> next = NULL;
    return headNode
}

创建结点

创建一个结点,结点的数据域必须有值

Node* CreateElem(int data){
    Node* Newelme = (Node*)malloc(sizeof(Node));
    Newelem -> data = data;
    Newelem -> next = NULL;
    return Newelem;
}

插入结点

头插法


尾插法


void InsertList(Node* headList,int data);
Node* P = CreatElme();
P -> next = headList -> next;
headList -> next = P;

打印结点

void PrintList(Node* HeadList){
    Node* Pmov = HeadList -> next;
    while(Pmov){
        printf("%d",Pmov.data);
        Pmov = Pmov -> next;
    }
}

删除结点


Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now