惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
A
About on SuperTechFans
Y
Y Combinator Blog
V
V2EX
Engineering at Meta
Engineering at Meta
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
V
Visual Studio Blog
博客园 - 叶小钗
博客园 - 聂微东
阮一峰的网络日志
阮一峰的网络日志
H
Help Net Security
小众软件
小众软件
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
The GitHub Blog
The GitHub Blog
WordPress大学
WordPress大学
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
MongoDB | Blog
MongoDB | Blog
B
Blog
G
Google Developers Blog
J
Java Code Geeks
博客园 - 三生石上(FineUI控件)
IT之家
IT之家
N
Netflix TechBlog - Medium
腾讯CDC

博客园 - ________囧丶殇

django系列 - 安装和新建项目 SQL - 基础 javascript刷新父页面 SQL - 约束 C语言(8) - 反转单向链表 C语言(6) - 各种排序算法的比较 C语言(5) - 选择排序 快速排序 C语言(4) - 插入排序 C语言(3) - 冒泡排序 归并排序 C语言(2) - 从指针开始 C语言(1) - 开始之前 python实践 - 抓取网页中的图片和数据 python实践 - 下载文件 python补充(2) - 内置函数 python补充(1) python笔记(十) - 异常和文件处理 python笔记(九) - 类 part2 python笔记(八) - 类 part1 python笔记(七) - and和or
C语言(7) - 数据结构之单向链表
________囧丶殇 · 2009-06-10 · via 博客园 - ________囧丶殇

/*
beango
2009-6-10 
*/
#include 
<stdio.h>

typedef 

struct _Node
{
    
int data;
    
struct _Node* next;
}Node;

typedef 

struct _List
{
    Node
* head;
}List;

List list;

//增加节点到链表的最未端
void Insert(Node* node)
{
    Node
* _head = list.head;
    
if (_head==NULL)
    {list.head 
= node;node->next = NULL;}
    
else
    {
        Node
* _node = _head;
        
while (_node->next!=NULL)
            _node 
= _node->next;
        _node
->next = node;
        node
->next = NULL;
    }
}
//获取索引处的元素
Node* getItem(int index)
{
    
if (index>=0)
    {
        
if (index==0)
        {
            
return list.head;
        }
        
else
        {
            Node
* node = list.head;
            
while (index-->0)node = node->next;
            
return node;
        }
    }
}
//输出链表
void ToString()
{
    Node
* _node = list.head;
    
if (_node!=NULL)
    {
        printf(
"%2d",_node->data);
        
while (_node->next!=NULL)
        {
            _node 
= _node->next;
            printf(
"%2d ",_node->data);
        }
    }
}
int main(void)
{
    Node node0 
={0,NULL};
    Insert(
&node0);

    Node node1 

= {1,NULL};
    Insert(
&node1);

    Node node2 

= {2,NULL};
    Insert(
&node2);

    Node node3 

= {3,NULL};
    Insert(
&node3);
    ToString();
int _itenIndex = 2;
    Node
* _item = getItem(_itenIndex);
    printf(
"\nlist[%d]=%d\n",_itenIndex,_item->data);
    
return 0;
}