链表一(单链表)

来源:互联网 发布:手机的视频剪辑软件 编辑:程序博客网 时间:2024/06/05 16:53

链表就一些包含数据的独立数据结构的集合。

链表创建:

typedef  struct NODE {struct  NODE  *link;int  value;}  Node;
但链表可以通过链从开始位置遍历链表直到结束位置,但链表无法从相反的方向进行遍历。

#include<stdlib.h>#include<stdio.h>#include "sll_node.h"#define FALSE 0;#define TRUE 1;int sll_insert(Node **rootp, int new_value){<span style="white-space:pre"></span>Node *current;Node *previous;Node *new;<span style="white-space:pre"></span>current = *rootp;<span style="white-space:pre"></span>previous = NULL;<span style="white-space:pre"></span>while(current != NULL && current->value < new_value){previous = current;current = current->link;}new = (Node *)malloc(sizeof(Node));if(new == NULL){return FALSE;}new->value = new_value;new->link = current;<span style="white-space:pre"></span>if(previous == NULL)<span style="white-space:pre"></span>*rootp = new;<span style="white-space:pre"></span>else<span style="white-space:pre"></span>previous->link = new;return TRUE;}









0 0
原创粉丝点击