C语言:将字符串中的字符逆序输出,但不改变字符串中的内容。-在main函数中将多次调用fun函数,每调用一次,输出链表尾部结点中的数据,并释放该结点,使链表缩短。
2024-09-30 15:27:25
//将字符串中的字符逆序输出,但不改变字符串中的内容。
#include <stdio.h> /************found************/
void fun (char *a)
{ if ( *a )
{ fun(a+) ;//使用递归进行数组的逆序输出。
/************found************/
printf("%c",*a) ;
}
} void main( )
{ char s[]="abcd";
printf("处理前字符串=%s\n处理后字符串=", s);
fun(s); printf("\n") ;
}
//已经建立了一个带头结点的单向链表,在main函数中将多次调用fun函数,每调用一次,输出链表尾部结点中的数据,并释放该结点,使链表缩短。
#include <stdio.h>
#include <stdlib.h>
#define N 8
typedef struct list//定义一个结构体
{ int data;
struct list *next;
} SLIST; void fun( SLIST *p)
{ SLIST *t, *s;
t=p->next; s=p;
while(t->next != NULL)
{ s=t;
/**********found**********/
t=t->next;
}
/**********found**********/
printf(" %d ",*t);//或者t->data
s->next=NULL;
/**********found**********/
free(t);//释放
}
SLIST *creatlist(int *a)
{ SLIST *h,*p,*q; int i;
h=p=(SLIST *)malloc(sizeof(SLIST));
for(i=; i<N; i++)
{ q=(SLIST *)malloc(sizeof(SLIST));
q->data=a[i]; p->next=q; p=q;
}
p->next=;
return h;
}
void outlist(SLIST *h)
{ SLIST *p;
p=h->next;
if (p==NULL) printf("\nThe list is NULL!\n");
else
{ printf("\nHead");
do { printf("->%d",p->data); p=p->next; } while(p!=NULL);
printf("->End\n");
}
}
void main()
{ SLIST *head;
int a[N]={,,,,,,,};
head=creatlist(a);//创建头结点
printf("\nOutput from head:\n"); outlist(head);
printf("\nOutput from tail: \n");
while (head->next != NULL){
fun(head);
printf("\n\n");
printf("\nOutput from head again :\n"); outlist(head);
}
}
最新文章
- javascript_this的用法
- Java小陷阱
- MVC小系列(十三)【全局异常处理与异常日志】
- 分页技术之PageDataSource类
- 一维DFT
- [Asp.net]常见word,excel,ppt,pdf在线预览方案(转)
- 源码安装apache及配置转发
- nyoj587 hdu1045 简单深搜
- vim 基本命令入门
- 「SCOI2015」小凸玩密室 解题报告
- 稳压二极管&;TVS二极管
- Struts2不扫描jar包中的action
- Html.RenderPartial(";";)与Html.Partial(";";)区别
- as3 单例的不常见写法
- Oracle - 为子查询提供动态结果集
- R语言学习笔记—决策树分类
- Gson 解析JSON数据
- Shell输出颜色设置
- nginx keepalive 双机
- 灯塔AOI简易实现
热门文章
- python setup.py 安装和卸载 的正确姿势
- 使用Powershell开机启动隐藏窗口的程序
- C#中获取时间戳
- HTTPSConnectionPool(host=&#39;files.pythonhosted.org&#39;, port=443): Read timed out的解决方法
- html div四边阴影效果
- 第四十六篇 入门机器学习——kNN - k近邻算法(k-Nearest Neighbors)
- selenium自动化之加载浏览器配置文件
- rke安装k8s cluster配置
- 【C语言】请输入一个n(n<;=10)并输出一个n行n列的杨辉三角
- 【visio】数据可视化 - 形状数据