链表的实现与原理
2016-07-10 15:37
211 查看
</pre> 链表是一种线性表,是通过指针与数据综合的组成的一种数据结构。可分为单链表与双链表</p><p> 链表的创建:</p><p> <pre name="code" class="cpp">#include <iostream>
using namespace std;
struct Node
{
ELEM data;
Node* next;
};
Node* creatList( int n )
{
Node* head, * tail, * temp;
head=NULL;
tail=NULL;
ELEM datetemp;
for(int i=0;i<n;i++)
{
temp = new Node;
cin>>datatemp;
temp=datatemp;
if(head==NULL)
{
tail=head=temp;
}
else
{
tail->next=temp;
tail=temp;
}
}
return head;
}
int main()
{
//TO DO for test
return 0;
}
using namespace std;
struct Node
{
ELEM data;
Node* next;
};
Node* creatList( int n )
{
Node* head, * tail, * temp;
head=NULL;
tail=NULL;
ELEM datetemp;
for(int i=0;i<n;i++)
{
temp = new Node;
cin>>datatemp;
temp=datatemp;
if(head==NULL)
{
tail=head=temp;
}
else
{
tail->next=temp;
tail=temp;
}
}
return head;
}
int main()
{
//TO DO for test
return 0;
}
相关文章推荐
- C#数据结构之顺序表(SeqList)实例详解
- Lua教程(七):数据结构详解
- 解析从源码分析常见的基于Array的数据结构动态扩容机制的详解
- C#数据结构之队列(Quene)实例详解
- C#数据结构揭秘一
- C#数据结构之单链表(LinkList)实例详解
- 数据结构之Treap详解
- 用C语言举例讲解数据结构中的算法复杂度结与顺序表
- C#数据结构之堆栈(Stack)实例详解
- C#数据结构之双向链表(DbLinkList)实例详解
- JavaScript数据结构和算法之图和图算法
- Java数据结构及算法实例:冒泡排序 Bubble Sort
- Java数据结构及算法实例:插入排序 Insertion Sort
- Java数据结构及算法实例:考拉兹猜想 Collatz Conjecture
- java数据结构之java实现栈
- java数据结构之实现双向链表的示例
- Java数据结构及算法实例:选择排序 Selection Sort
- Java数据结构及算法实例:朴素字符匹配 Brute Force
- Java数据结构及算法实例:汉诺塔问题 Hanoi
- Java数据结构及算法实例:快速计算二进制数中1的个数(Fast Bit Counting)