c语言链表统计的函数 c语言链表统计的函数有哪些

c语言,编写一个函数统计英文句子中字母的个数 , 将英语句子存入到链表中功能:按你要求写的,输入句子存入链表,统计字母个数 。
#includestdio.h
#includemalloc.h
typedef struct word
{
char c;
struct word *next;
}WD;
int newWD(WD *wdHead,WD *wdTail)//输入字符存入链表返回输入个数参数:链表头指针尾指针
{
static int count;
char c;
scanf("%c",c);
if(c=='\n')
return 0;
WD *wdNew=(WD *)malloc(sizeof(WD));
wdNew-c=c;
wdNew-next=NULL;
if(wdHead-next==NULL)
{
count=0;
wdHead-next=wdTail=wdNew;
}
else
{
wdTail-next=wdNew;
wdTail=wdNew;
}
if((c='A'c='Z')||(c='a'c='z'))
count;
newWD(wdHead,wdTail);
return count;
}
int main()
{
int count;
WD *wdHead=(WD *)malloc(sizeof(WD));
wdHead-next=NULL;
WD *wdTail=NULL;
count=newWD(wdHead,wdTail);
【c语言链表统计的函数 c语言链表统计的函数有哪些】printf("输入的句子为:\n");
while(wdHead-next!=NULL)
{
printf("%c",wdHead-next-c);
wdHead=wdHead-next;
}
printf("\n");
printf("输入的字母个数为:%d个\n",count);
return 0;
}
关于c语言链表函数#includestdio.h#includewindows.h#include stdio.h#include malloc.h#include stdlib.h//定义数据类型名称typedef int DataType;#define flag -1//定义数据输入结束c语言链表统计的函数的标志数据//单链表结点存储结构定义typedef struct Node{DataType data;struct Node *next;}LNode ,*LinkList;//建立单链表子函数 LNode *Create_LinkList(){LNode *s,*head,*L;int i=0,x;//定义指向当前插入元素c语言链表统计的函数的指针while(1){scanf("%d",x);if(-1==x){return head;break;}s= (LNode *)malloc(sizeof(LNode));//为当前插入元素的指针分配地址空间s-data =https://www.04ip.com/post/x;s-next =NULL;i;if(i==1)head=s;elseL-next =s;L=s;}}//查找子函数(按序号查找)LNode *Get_LinkList(LinkList L,int i){LNode *p;int j;//j是计数器c语言链表统计的函数,用来判断当前的结点是否是第i个结点p=L;j=1;while(p!=NULLji){p=p-next ;//当前结点p不是第i个且p非空c语言链表统计的函数,则p移向下一个结点j;}return p;}//插入运算子函数void Insert_LinkList(LinkList L,int i,DataType x)//在单链表L中第i个位置插入值为x的新结点{LNode *p,*s;p =Get_LinkList(L,i);//寻找链表的第i-1个位置结点if(p==NULL){printf("插入位置不合法!");exit(-1);}else{s= (LinkList)malloc(sizeof(LNode));//为当前插入元素的指针分配地址空间s-data =https://www.04ip.com/post/x;s-next =p-next ;p-next =s;}}//单链表的删除运算子函数void Delete_LinkList(LinkList L,int i)//删除单链表上的第i个结点{LNode *p,*q;p=Get_LinkList(L,i-1);//寻找链表的第i-1个位置结点if(p==NULL){printf("删除的位置不合法!");//第i个结点的前驱结点不存在,不能执行删除操作exit(-1);}else{if(p-next ==NULL){printf("删除的位置不合法!");//第i个结点不存在 , 不能执行删除操作exit(-1);}else{q=p-next ;p-next =p-next-next;free(q);}}}//求表长运算子函数int Length_LinkList(LinkList L){int l;//l记录L的表长LNode *p;p=L;l=1;while(p-next){p=p-next;l;}return l;}int main (){LNode *head,*p;head=(LinkList)malloc(sizeof(LNode));int x,y;a:printf("*******menu*******\n");printf("**创建**********1*\n");printf("**插入**********2*\n");printf("**删除**********3*\n");printf("**表长**********4*\n");printf("**清屏**********5*\n");printf("**打印**********6*\n");printf("**退出******other*\n");printf("******************\n");int i=1;while(i){printf("请输入选项c语言链表统计的函数:");scanf("%d",i);switch(i){case 1:head=Create_LinkList(); getchar();break;case 2:printf("请输入位置和数据;");scanf("%d%d",x,y);Insert_LinkList(head,x,y);break;case 3:printf("请输入位置;");scanf("%d",x);Delete_LinkList(head,x);break;case 4:printf("%d",Length_LinkList(head));break;case 5:system("cls");goto a;case 6:p=head;while(p!=NULL){printf("%d\n",p-data);p=p-next;}break;default :i=0;}}}
我把创建给改了一下
统计链表中正数和负数的个数 C语言编程设计#include stdio.h
#include stdlib.h
typedef struct node {
int value;
struct node *next;
} NODE;
NODE *create();
void print_link(NODE *);
void count(NODE *, int *, int *);
NODE *create_zh(NODE *);
void main(){
NODE *p, *q;
int z_num, f_num;
p = create();
if(p==NULL) {
printf("链表是空的c语言链表统计的函数!");
return;
}
print_link(p);
count( p,z_num,f_num);//请填写调用count函数的实际参数
printf("正数个数为 %d, 负数个数为 %d\n", z_num, f_num);
q=create_zh(p);
if(q==NULL) {
printf("正数链表是空的c语言链表统计的函数!");
return;
}
print_link(q);
}
NODE *create()//创建链表的函数
{
NODE *h=NULL, *p=NULL;
int x;scanf("%d", x);
while(x!=0) {
p=(NODE *)malloc(sizeof(NODE));
if(p==NULL)return h;
p-value = https://www.04ip.com/post/x;
p-next = h;
h = p;
scanf("%d", x);
}
return h;
}
void print_link(NODE *p)//输出链表的函数
{
while(p!=NULL) {
printf("%d, ", p-value);
p = p-next;
}
printf("\n");
}
void count(NODE *p, int *n1, int *n2)// 统计正数和负数的计数函数
{
*n1=*n2=0;
while (p)
{
if (p-value0)
*n1 =1;
else
*n2 =1;
p=p-next;
}
}
NODE *create_zh(NODE *p)//创建正数单链表函数
{
NODE *h=NULL, *m=NULL;
while(p) {
if(p-value0){
m=(NODE *)malloc(sizeof(NODE));
m-value=https://www.04ip.com/post/p-value;
m-next=h;
h=m;
}
p=p-next;
}
return h;
}
(数据结构C语言版)编写一个函数,统计某一特定元素value在单链表中出现的次数(元素为int型)int frequency(Linklist L,int value)
{
int cnt=0;
struct node *p=L;
while(p)
{
if(p-data=https://www.04ip.com/post/=value)
{
cnt;
}
p=p-next;
}
return cnt;
}
c语言链表统计的函数的介绍就聊到这里吧,感谢你花时间阅读本站内容 , 更多关于c语言链表统计的函数有哪些、c语言链表统计的函数的信息别忘了在本站进行查找喔 。

    推荐阅读