基本Link List 用C語言實現

先附上標頭檔

 /**
* @author Chen-Hao Lin
* @email westgate.skater@gmail.com
* @website   https://www.cnblogs.com/ollie-lin
* @link     https://www.cnblogs.com/ollie-lin/p/9927405.html
* @version v1.0
* @ide CodeBlocks 17.12
* @license GUN GCC
* @brief link list template
* @file Linklist.h
*/ #include <stdlib.h>
#include <stdio.h> /**
* @defgroup Link list node
* @brief
* @{
*/ typedef struct node
{
int data;
struct node * next;
}Node; /**
* @brief Create link list.
* @param arr: pointer to integer data array. link list data array to assign link list data.
* @param size: describe data array size
* @retval first link list node.
*/
Node *CreateList(int *arr, int size); /**
* @brief Show all of link list.
* @param *node: print link list form this node.
* @retval None
*/
void PrintList(Node *node); /**
* @brief Release link list space.
* @param *node: Release link list form this node.
* @retval None
*/
void FreeList(Node *node); /**
* @brief Search the specific node.
* @param *node: Search the specific node form this pointer.
* @param data: Search the specific node information.
* @retval find the specific node
*/
Node *SearchNode(Node *node, int data); /**
* @brief Insert node
* @param *node: Insert node after the this param.
* @param item: Search data of specific node to insert node.
* @param data: The data of Insert node.
* @retval None
*/
void InsertNode(Node *node, int item, int data); /**
* @brief Before insert node at first node.
* @param *node: first node
* @param data: The data of Insert node.
* @retval first node
*/
Node *Push_front(Node *node, int data); /**
* @brief Insert node at last
* @param *node: form last node
* @param data: The data of last node.
* @retval None
*/
void Push_back(Node *node, int data);

各項功能實做 Create List

 Node * CreateList(int *arr, int size)
{
if(arr == || size == )
return NULL; Node *previous, *first;
for(int i = ; i < size; i++)
{
Node *current = (Node*)malloc(sizeof(Node));
current->data = arr[i]; if(i == )
first = current;
else{
previous->next = current;
}
current->next = NULL;
previous = current;
}
return first;
}

PrintList

 void PrintList(Node *node)
{
if(node == ){
printf("List is empty.\n");
return;
} Node *current = node;
while(current)
{
printf("%d ", current->data);
current = current->next;
}
printf("\n");
}

Release List

 void FreeList(Node *node)
{
Node *current, *temp;
current = node;
while(current)
{
temp = current;
current = current->next;
free(temp);
}
}

Search node

 Node *SearchNode(Node *node, int data)
{
Node *temp = node;
while(temp)
{
if(temp->data == data)
return temp;
else
temp = temp->next;
}
return NULL;
}

Insert node

 void InsertNode(Node *node, int item, int data)
{
Node *current = node;
Node *previous = (Node*)malloc(sizeof(Node));
Node *newNode = (Node*)malloc(sizeof(Node));
while(current)
{
if(current->data == item)
{
newNode->data = data;
previous->next = newNode;
newNode->next = current;
break;
}
else
{
previous = current;
current = current->next;
}
}
}

push front/back node

 Node* Push_front(Node *node, int data)
{
Node *temp = (Node*)malloc(sizeof(Node));
temp->data = data;
temp->next = node;
node->next = node->next;
return temp;
} void Push_back(Node *node, int data)
{
Node *newNode = (Node*)malloc(sizeof(Node));
newNode->data = data;
while(node->next)
{
node = node->next;
}
node->next = newNode;
newNode->next = NULL;
}

(C/C++) Link List - C 語言版本的更多相关文章

  1. GO語言基礎教程:序章

    首先自我介紹一下我自己,我是一個coder,目前主要從事B/S程序開發工作,懂點PHP;ASP;JSP;JS;VB;C;DELPHI;JAVA,另外知道幾個數據庫,除此之外別無所長,那麼我為何會選擇學 ...

  2. 幾個步驟輕鬆在windows操作系統上搭建GO語言開發環境

    1. 首先下载官方GO語言安装包: https://code.google.com/p/go/wiki/Downloads?tm=2 2. 设置 GOPATH 在任意磁盘根目录新建一个文件夹,名字随意 ...

  3. GO語言基礎教程:數組,切片,map

    這節課我們來講解數組,切片和map,或許您是從其他語言轉到GO語言這邊的,那麼在其他語言的影響下您可能會不太適應GO語言的數組,因為GO語言把數組給拆分成了array,slice和map,接下來的時間 ...

  4. GO語言基礎教程:流程控制

    在開始一個新的章節之前先來回顧上一篇文章的部份,首先我們來看這段代碼: package main import ( "fmt" ) func main(){ var x,y int ...

  5. GO語言基礎教程:數據類型,變量,常量

    GO類似PHP,每行的結尾要加分號來結束,不同點在於GO對此並不強制,這一點又像javascript,另外GO的語句塊是用一對大括號來包裹的,但是go要求左大括號必須要在語句的結尾處,不能在行首出現左 ...

  6. GO語言基礎教程:Hello world!

    首先簡單地說一下GO語言的環境安裝,從 http://golang.org/dl/ 針對自己的操作系統選擇合適的安裝包,然後下載安裝即可,下載的時候注意別選錯了的操作系統,例如go1.3.1.darw ...

  7. Ubuntu語言支持爲灰色修復方法

    Ubuntu語言支持爲灰色修復方法 在Ubuntu12.04中,在下不知爲何將 語言支持 中 應用到整個系統 和 添加語言 這2個按弄成了灰色,導致ibus不能輸入中文,現在唔將修復方法公告天下: 1 ...

  8. Python 面向導向語言 Object Oriented Programming Language

    Pytho 是面向對象的程式語言,舉凡 Literals 值都是 Object.例如: >>> id(38)8791423739696 與 >>> id('ABC' ...

  9. C/C++語言 - 日常算法 - 蛇形填數

    C/C++語言 - 日常算法 - 蛇形填數 日期 : 2019-06-11 問題描述: 在n×n方阵里填入1,2,…,n×n,要求填成蛇形. 例如,n=4时方阵为: 10   11  12  1 9 ...

随机推荐

  1. log4j配置文件的手动加载与配置初始化

    一. 本地项目: 初始化log4j的日志配置,指定到src目录下(建议用2)         //1. 本地项目-属性文件配置         PropertyConfigurator.configu ...

  2. 【HDU4970】Killing Monsters

    题意 数轴上有n个点,有m座炮塔,每个炮塔有一个攻击范围和伤害,有k个怪物,给出他们的初始位置和血量,问最后有多少怪物能活着到达n点.n<=100000 分析 对于某个怪物,什么情况下它可以活着 ...

  3. php 扩展开发

    Linux下用C开发PHP扩展 一.首先下载PHP源码包,假设源码包目录为:/software/php-5.2.13 #> cd /software/php-5.2.13/ext 二.假设我们要 ...

  4. Lambda01 编程范式、lambda表达式与匿名内部类、函数式接口、lambda表达式的写法

    1 编程范式 主要的编程范式有三种:命令式编程,声明式编程和函数式编程. 1.1 命令式编程 关注计算机执行的步骤,就是告诉计算机先做什么后做什么 1.2 声明式编程 表达程序的执行逻辑,就是告诉计算 ...

  5. 557. Reverse Words in a String III 翻转句子中的每一个单词

    [抄题]: Given a string, you need to reverse the order of characters in each word within a sentence whi ...

  6. ZendStudio 代码调试

    F5.单步调试进入函数内部(单步进入)F6.单步调试不进入函数内部(跳过)F7.由函数内部返回到调用处(跳出) F8.一直执行到下一个断点Ctrl+F2:结束调试

  7. IDEA+DevTools实现热部署功能

      开发IDE: Intellij IDEA 2018.1 SpringBoot:1.5.9.RELEASE 热部署 大家都知道在项目开发过程中,常常会改动页面数据或者修改数据结构,为了显示改动效果, ...

  8. 编写高质量代码改善C#程序的157个建议——建议51:具有可释放字段的类型或拥有本机资源的类型应该是可释放的

    建议51:具有可释放字段的类型或拥有本机资源的类型应该是可释放的 在建议50中,我们将C#中的类型分为:普通类型和继承了IDisposable接口的非普通类型.非普通类型除了包含那些托管资源的类型外, ...

  9. LibreOJ 6000 搭配飞行员(最大流)

    题解:最基础的最大流,按照主飞行员与起点建边,副飞行员与终点建边,可以同坐的主副飞行员之间建边,值均为一,然后跑一边最大流就完美了! 代码如下: #include<queue> #incl ...

  10. POJ-3481 Double Queue (splay)

    The new founded Balkan Investment Group Bank (BIG-Bank) opened a new office in Bucharest, equipped w ...