栈的定义:当单链表限定只能在头部进行插入和删除操作的时候,就是链栈。同时把栈顶放在单链表的头部,使单链表的头指针和栈顶指针top合二为一,所以对于链栈,就不再需要头结点了。这时对链栈的push也就相当于单链表的头插法。同时对链栈来说,基本不存在栈满的情况,除非内存已经没有可以使用的空间了,对于空栈来...
分类:
其他好文 时间:
2015-02-10 01:50:43
阅读次数:
129
改写要求1:改写为以单链表和双向链表存储二维数组改写要求2:添加函数SingleLinkProcess()实现互换单链表中最大结点和头结点位置,最小结点和尾结点位置改写要求3:添加函数DoubleLinkProcess()实现互换双向链表中最大结点和头结点位置,最小结点和尾结点位置#include ...
分类:
编程语言 时间:
2015-02-09 00:45:43
阅读次数:
213
/*多项式加法运算使用链表实现*/#include using namespace std;//使用不带头结点的单向链表,按照指数递减的顺序排列typedef struct PolyNode{ int coef; //系数 int expon; //指数 PolyNod...
分类:
其他好文 时间:
2015-02-05 20:03:39
阅读次数:
111
Q:
You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as ...
分类:
其他好文 时间:
2015-02-02 23:06:26
阅读次数:
153
Merge k sorted
linked lists and return it as one sorted list. Analyze and describe its complexity.
解题思路:一般而言,合并两个有序链表较为简单,只需要两两逐个比较即可.而本题要求合并K个有序链表,事实上只需要对每个链表的头结点建堆.每次输出最小值.并插入其所在链表的下个结点并维护堆.可以利用S...
分类:
其他好文 时间:
2015-01-31 14:40:42
阅读次数:
190
//1.初始化:(有头结点的情况下)
S=(LStack*)malloc(sizeof(LStack));//为栈开辟内存空间
S.next=NULL;//把栈置为空
//2.入栈
p=(LStack*)malloc(sizeof(Lstack));//给入栈的元素分配内存空间
p->data=e;//把元素e插入栈内
p->next=S->next;//使得e成为了栈顶元素
S->next=p;...
分类:
其他好文 时间:
2015-01-30 22:48:45
阅读次数:
213
题目:
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first
two lists.
我的解法:
(1)算法思想:
先根据两个链表l1,l2头结点值的大小设置要返回链表的头结点h...
分类:
其他好文 时间:
2015-01-29 17:44:28
阅读次数:
116
//---单链表的单链式存储结构----
typedef struct LNode
{
ElemType data;
struct LNode *next;
}LNode,*LinkList;
//1.初始化
int Initlist(LinkList L)
{
L=NULL;
return OK;
}
//初始化(带头结点)
int Initlist(LinkList L)
{
L...
分类:
其他好文 时间:
2015-01-29 12:43:17
阅读次数:
257
一、链表头结点:知道链表第一个元素的位置,就知道链表的位置,故在插入元素函数的参数用指针的指针**phead,这样空链表时*phead=newnode,否则需要消耗一个空节点的空间(参数*headnode,在头插入是headnode->next=new)。如果参数为*phead,空链表时phead=...
分类:
其他好文 时间:
2015-01-28 17:38:00
阅读次数:
377
题目:
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together
the nodes of the first two lists.
思路:
设置两个头指针,一个指针不动,用来返回最后头结点,一个指针用来组织节点顺序,遍...
分类:
其他好文 时间:
2015-01-25 18:18:40
阅读次数:
203