(C/C++) Link List - C 語言版本
基本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 語言版本的更多相关文章
- GO語言基礎教程:序章
		首先自我介紹一下我自己,我是一個coder,目前主要從事B/S程序開發工作,懂點PHP;ASP;JSP;JS;VB;C;DELPHI;JAVA,另外知道幾個數據庫,除此之外別無所長,那麼我為何會選擇學 ... 
- 幾個步驟輕鬆在windows操作系統上搭建GO語言開發環境
		1. 首先下载官方GO語言安装包: https://code.google.com/p/go/wiki/Downloads?tm=2 2. 设置 GOPATH 在任意磁盘根目录新建一个文件夹,名字随意 ... 
- GO語言基礎教程:數組,切片,map
		這節課我們來講解數組,切片和map,或許您是從其他語言轉到GO語言這邊的,那麼在其他語言的影響下您可能會不太適應GO語言的數組,因為GO語言把數組給拆分成了array,slice和map,接下來的時間 ... 
- GO語言基礎教程:流程控制
		在開始一個新的章節之前先來回顧上一篇文章的部份,首先我們來看這段代碼: package main import ( "fmt" ) func main(){ var x,y int ... 
- GO語言基礎教程:數據類型,變量,常量
		GO類似PHP,每行的結尾要加分號來結束,不同點在於GO對此並不強制,這一點又像javascript,另外GO的語句塊是用一對大括號來包裹的,但是go要求左大括號必須要在語句的結尾處,不能在行首出現左 ... 
- GO語言基礎教程:Hello world!
		首先簡單地說一下GO語言的環境安裝,從 http://golang.org/dl/ 針對自己的操作系統選擇合適的安裝包,然後下載安裝即可,下載的時候注意別選錯了的操作系統,例如go1.3.1.darw ... 
- Ubuntu語言支持爲灰色修復方法
		Ubuntu語言支持爲灰色修復方法 在Ubuntu12.04中,在下不知爲何將 語言支持 中 應用到整個系統 和 添加語言 這2個按弄成了灰色,導致ibus不能輸入中文,現在唔將修復方法公告天下: 1 ... 
- Python 面向導向語言 Object Oriented Programming Language
		Pytho 是面向對象的程式語言,舉凡 Literals 值都是 Object.例如: >>> id(38)8791423739696 與 >>> id('ABC' ... 
- C/C++語言 - 日常算法 - 蛇形填數
		C/C++語言 - 日常算法 - 蛇形填數 日期 : 2019-06-11 問題描述: 在n×n方阵里填入1,2,…,n×n,要求填成蛇形. 例如,n=4时方阵为: 10 11 12 1 9 ... 
随机推荐
- RichEdit在Win8上乱码
			之前的一个项目中使用了RichEdit,发现在Win8中输入中文乱码,但是复制粘贴正常. 经过各种搜索调查,发现是msftedit.dll的问题,我在win7上找到msftedit.dll,将它拷贝到 ... 
- Mac下切换Python版本
			Mac下有多个版本的Python时,需要进行版本切换.我使用的是anaconda,在终端下进行包安装时,默认Python版本是MacOS自带的Python,需要进行手动的版本切换. # 将anacon ... 
- 利用osmosis导出osm城市数据
			转载(未测试) 方法核心就是利用osmosis的导出指定功能,即是从大范围导出小范围的基本用例. 我们只需要知道我们所需要提取的城市的经纬度范围, 例如广州市的经纬度范围是北纬22.26~23.56度 ... 
- 复习扩展方法 涉及委托,这里我使用自定义委托类型 public delegate bb MyFunc<in T,out bb> (T arg)
			using System;using System.Collections.Generic;using System.Data;using System.Linq;using System.Text; ... 
- HandleErrorAttribute只能处理httpStatusCode为500的异常(服务器异常)
			HandleErrorAttribute源代码: [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited ... 
- Java IO输入输出流 FileWriter 字符流
			字节缓冲流 //为什么要使用包装流,使用包装流是为了提高读写操作的性能. public class Packing_flowDemo { public static void main(String[ ... 
- (转)Asp.Net底层原理(三、Asp.Net请求响应过程)
			原文地址:http://www.cnblogs.com/liuhf939/archive/2013/09/16/3324753.html 在之前,我们写了自己的Asp.Net框架,对整个流程有了一个大 ... 
- POJ3233 Matrix Power Series(矩阵快速幂+分治)
			Description Given a n × n matrix A and a positive integer k, find the sum S = A + A2 + A3 + … + Ak. ... 
- java多线程的操作
			上篇博客简单了介绍了Java的多线程的概念,与进程的区别,两种创建方式,状态及获取线程名称等内容.这篇文章接着介绍Java的多线程.主要从一下几方面介绍. 1 线程类的常用方法 1.1 start() ... 
- Thumbnail 图片帮助
			public class Thumbnail { private Image srcImage; private string srcFileName; /// <summary> /// ... 
