基本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. 解决Maximum execution time of 120 seconds exceeded

    在循环开始前加入代码: //设置超时时间 ini_set("max_execution_time",18000); set_time_limit(0); set_time_limi ...

  2. solr facet查询及solrj 读取facet数据(相当有用)

    原文出自:http://www.coin163.com/java/docs/201310/d_3010029802.html 一.   Facet 简介 Facet 是 solr 的高级搜索功能之一  ...

  3. 刷题向》DP》放苹果 (normal)

    这篇博客可能字数比较多,而且很难讲清楚,我会努力给你们讲清楚: 首先,放苹果是一道DP,之所以难,是因为很难想到,我的确有同学用三维数组做出来,然而三维的的确比二维好理解,但三维复杂度太高,虽然DP一 ...

  4. 分布式基础学习【二】 —— 分布式计算系统(Map/Reduce)

    二. 分布式计算(Map/Reduce) 分布式式计算,同样是一个宽泛的概念,在这里,它狭义的指代,按Google Map/Reduce框架所设计的分布式框架.在Hadoop中,分布式文件系统,很大程 ...

  5. TOP命令 详解CPU 查看多个核心的利用率按1

    top命令是linux下常用的工具,可以查看各个进程的CPU使用情况.先看一个实例: 这是Ramnode双核VPS的top显示结果: 左上角可以看到CPU的使用率是11.3%,但是看下面的进程,plu ...

  6. java基础面试题 背过1

    web.xml文件中可以配置哪些内容? 答:web.xml用于配置Web应用的相关信息,如:监听器(listener) ContextLoaderListener .过滤器(filter) Strut ...

  7. Django框架 之 Pagination分页实现

    Django框架 之 Pagination分页实现 浏览目录 自定义分页 Django内置分页 一.自定义分页 1.基础版自定义分页 1 2 3 4 5 6 7 8 9 10 11 12 13 14 ...

  8. javascript总结16:数组array12

    1 Array 对象 作用:Array 对象用于在变量中存储多个值. 1.1 数组定义 var ary = new Array();//通过创建对象的方式创建数组 var ary1 = [];// 直 ...

  9. UVa 1625 Color Length (DP)

    题意:给定两个序列,让你组成一个新的序列,让两个相同字符的位置最大差之和最小.组成方式只能从一个序列前部拿出一个字符放到新序列中. 析:这个题状态表示和转移很容易想到,主要是在处理上面,dp[i][j ...

  10. HTML5拓扑3D机房,电力工控Web SCADA

    http://www.hightopo.com/cn-index.html 一套丰富的JavaScript界面类库, 提供完整的基于HTML5图形界面组件库.使用HT for Web您可以轻松构建现代 ...