C语言:将字符串中的字符逆序输出,但不改变字符串中的内容。-在main函数中将多次调用fun函数,每调用一次,输出链表尾部结点中的数据,并释放该结点,使链表缩短。
//将字符串中的字符逆序输出,但不改变字符串中的内容。
#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);
}
}
C语言:将字符串中的字符逆序输出,但不改变字符串中的内容。-在main函数中将多次调用fun函数,每调用一次,输出链表尾部结点中的数据,并释放该结点,使链表缩短。的更多相关文章
- pojg2744找一个最长的字符串x,使得对于已经给出的字符串中的任意一个y,x或者是y的子串,或者x中的字符反序之后得到的新字符串是y的子串。
http://poj.grids.cn/practice/2744 描述现在有一些由英文字符组成的大小写敏感的字符串,你的任务是找到一个最长的字符串x,使得对于已经给出的字符串中的任意一个y,x或者是 ...
- PTA 将数组中的数逆序存放
7-1 将数组中的数逆序存放 (20 分) 本题要求编写程序,将给定的n个整数存入数组中,将数组中的这n个数逆序存放,再按顺序输出数组中的元素. 输入格式: 输入在第一行中给出一个正整数n(1). ...
- java笔试之字符逆序(二)
与字符逆序(一)不同,句子逆序,单词顺序.例如:I am a student 输出为student a am I. 想法:先字符串句子逆序,然后针对每个单词再逆序一遍. package test; i ...
- python列表和字符串的三种逆序遍历方式
python列表和字符串的三种逆序遍历方式 列表的逆序遍历 a = [1,3,6,8,9] print("通过下标逆序遍历1:") for i in a[::-1]: print( ...
- leetcode——Reverse Linked List II 选择链表中部分节点逆序(AC)
Reverse a linked list from position m to n. Do it in-place and in one-pass. For example: Given 1-> ...
- java笔试之字符逆序(一)
将一个字符串str的内容颠倒过来,并输出.str的长度不超过100个字符. 如:输入“I am a student”,输出“tneduts a ma I”. package test; import ...
- 请实现一个函数用来匹配包括'.'和'*'的正则表达式。模式中的字符'.'表示任意一个字符,而'*'表示它前面的字符可以出现任意次(包含0次)。 在本题中,匹配是指字符串的所有字符匹配整个模式。例如,字符串"aaa"与模式"a.a"和"ab*ac*a"匹配,但是与"aa.a"和"ab*a"均不匹配
// test20.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include<iostream> #include< ...
- c语言,以单词为单位逆序字符串
#include "string.h" #include "stdio.h" char * nixu(char *c) { ; int n = strlen(c ...
- c数据结构栈的基本操作(字符逆序输出)
线性栈 输入字符,再输出 #include "stdafx.h" #include<stdlib.h> #include<malloc.h> #define ...
随机推荐
- python之路之html
def index(request): print request.POST print request.GET print request.FILES for item in request.FIL ...
- win7系统Java 开发环境配置
我的天啊,博客园写了两年九个月,终于有六个粉丝啦,哈哈哈哈哈哈哈哈哈,谢谢大家的关注 进入正题,java环境配置,我要学java了,人生在于瞎折腾. 久闻java大名,但是没接触过,但java环境配置 ...
- centos 7 pip install MySQL-python 报错
pip install MySQL-python 报错 pip install MySQL-python DEPRECATION: Python . Please upgrade your Pytho ...
- 老生常谈--Java值传递和引用传递
起因 前两天面试被问到了这个问题,虽然之前老早就了解过这个问题,但是并没有深入了解,所以面试的时候一下子慌了,菜是原罪,今天菜鸡来补补基础知识. 其实这个问题一直是被讨论的,常见的三种说法就是,1,J ...
- sqlserver 查看视图语句
本人sql小白一个,在项目中遇到了视图的使用,但是不知道视图的语句怎么查看,所以在网上搜索了一下,查到了一下的查看方式,再次记录一下: 方法一->前提: 已经创建好的视图 sp_helptext ...
- thinkphp的模型操作
先开个坑 WHERE篇 1, 模糊查询 where['keyword'] = [ 'like' , '%test%'] 2, 不等于,大于 ,小于 EQ 等于(=)NEQ 不等于(<& ...
- 线性递推BM模板
#include <cstdio> #include<iostream> #include <cstring> #include <cmath> #in ...
- opencv:二值图像的概念
灰度图像与二值图像 二值分割 #include <opencv2/opencv.hpp> #include <iostream> using namespace cv; usi ...
- 1.1Jmeter学习网站
在网上找到一些关于Jmeter学习的博客等,在此标记 一. chinaunix的一篇博客,讲的蛮详细的 http://blog.chinaunix.net/uid/26884465/cid-16819 ...
- vue 获得当前无素并做相应处理
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...