Revser single link example code
来源:互联网 发布:jquery 2.1.1.js下载 编辑:程序博客网 时间:2024/05/21 08:01
单链表倒序:
#include <stdio.h>
struct link
{
int value;
struct link * next;
} ;
void output_link(struct link * head)
{
printf(" ");
while(head != NULL)
{
printf(" [%d] ", head->value);
head = head->next;
}
}
void rever_output_link(struct link * head)
{
if(head) {
rever_output_link(head->next);
printf(" [%d] ",head->value);
}
}
struct link * create_link (int n)
{
struct link * head = malloc(sizeof(struct link));
struct link *tmp, * pre;
int i;
pre = head;
head->value = rand();
for( i = 0 ; i < n - 1; i ++ )
{
tmp = malloc(sizeof(struct link));
tmp->value = rand();
tmp ->next = NULL;
pre->next = tmp;
pre = pre->next ;
}
return head;
}
struct link * revert_link(struct link * head)
{
struct link * left, * mid , * tmp;
left = head ;
mid = head->next;
left->next = NULL;
while(mid != NULL)
{
tmp = mid->next ;
mid->next = left;
left = mid;
mid = tmp;
}
return left;
}
void del_link(struct link * head)
{
struct link * tmp;
while(head != NULL)
{
tmp = head;
head = head->next;
free(tmp);
}
}
int main()
{
struct link * head = create_link(6);
struct link * tmp ;
output_link(head);
tmp = revert_link(head);
output_link(tmp);
del_link(head);
return 0;
}
struct link
{
int value;
struct link * next;
} ;
void output_link(struct link * head)
{
printf(" ");
while(head != NULL)
{
printf(" [%d] ", head->value);
head = head->next;
}
}
void rever_output_link(struct link * head)
{
if(head) {
rever_output_link(head->next);
printf(" [%d] ",head->value);
}
}
struct link * create_link (int n)
{
struct link * head = malloc(sizeof(struct link));
struct link *tmp, * pre;
int i;
pre = head;
head->value = rand();
for( i = 0 ; i < n - 1; i ++ )
{
tmp = malloc(sizeof(struct link));
tmp->value = rand();
tmp ->next = NULL;
pre->next = tmp;
pre = pre->next ;
}
return head;
}
struct link * revert_link(struct link * head)
{
struct link * left, * mid , * tmp;
left = head ;
mid = head->next;
left->next = NULL;
while(mid != NULL)
{
tmp = mid->next ;
mid->next = left;
left = mid;
mid = tmp;
}
return left;
}
void del_link(struct link * head)
{
struct link * tmp;
while(head != NULL)
{
tmp = head;
head = head->next;
free(tmp);
}
}
int main()
{
struct link * head = create_link(6);
struct link * tmp ;
output_link(head);
tmp = revert_link(head);
output_link(tmp);
del_link(head);
return 0;
}
- Revser single link example code
- single link
- Single link list
- Another Single Link List
- <OJ_Sicily>Single-link Clustering
- Sicily Single-link Clustering
- Simple Lucene Example Code
- Driver development code example.
- java code example site
- Example code for LDD3
- An example code
- NSCopying & NSCoding Example Code
- RNTween code example
- RNTouchInput Example code
- drop procedure code example
- QTP code example
- Shell Code Example
- Core Animation Example Code
- 如何用全局变量得到类对象的指针
- VMware Player v1.0.6.80404,v2.0.3.80004
- BBS上题的算法
- 疯子:学习
- linux fstab 自动挂载分区(转)
- Revser single link example code
- 多线程,多在那呢?
- Becky!使用集要(0516版)
- 指向const对象的指针和const指针
- Becky!经典使用问题集(0516版)
- 爱,请在来得及的时候说出口
- 使用C++,还是了解点底层比较好~:)
- SQL Server连接中常见错误解决方法
- Shell十三问