生活随笔
收集整理的這篇文章主要介紹了
[数据结构]顺序单链表插入
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
一,單鏈表插入操作
?
[cpp]?view plaincopy
typedef?struct?NODE?{??????struct?NODE?*link;??????int?value;??}Node;????#include?<stdlib.h>??#include?<stdio.h>????#define?FALSE?0??#define?TRUE?1????int?s_insert(Node?**rootp,int?new_value)??{??????Node?*current;??????Node?*new;??????Node?*previous;????????????current?=?*rootp;??????previous?=?NULL;????????????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;??????if(previous?==?NULL)??????{??????????*rootp?=?new;??????}??????else??????{??????????previous->link?=?new;??????}??????return?TRUE;??} ?
轉(zhuǎn)載于:https://www.cnblogs.com/zhiliao112/p/4237195.html
總結(jié)
以上是生活随笔為你收集整理的[数据结构]顺序单链表插入的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。