用链表存储字符串 && 新建链表筛选

Description:

用链表A存储一组字符串([1, 80]),建立一个链表B,存储其中ASCLL码字符最小的数出现的次数等于n的字符串。

#include
#include
#include 

struct N
{
	char s[85];       //一开始定义成了char *s,下接[1];
	struct N *next;
    int t;               //t用来记录s中ascll码最小的数出现的次数
    
};

int t(char *s)                //计算s中ascll码最小的数出现的次数
{
	int len = strlen(s);
	char min = s[0];
	int t = 1;
	for(int i=1; i<=len-1; i++)
	{
		if(s[i]s);    //上接[1],对于char*s,没有办法正常循环输入,因为还未分配内存
		tmp->t = t(tmp->s);
		end->next = tmp;
		end = tmp; 
	}
	end->next = NULL;
	return headA;
}

struct N *createB(struct N* headA, int n)
{
	struct N *headB = (struct N*)malloc(sizeof(struct N));
	struct N *endB = headB;
	struct N *p = headA->next;
	while(p!=NULL)
	{
		if(p->t == n)
		{
			endB->next = p;
			endB = p;
		}
		p = p->next;
	}
	endB->next = NULL;
	return headB;
}

int main()
{
    int num;
    scanf("%d", &num);
    struct N *headA = createA(num); 
    int n;
    scanf("%d", &n);
	struct N *headB = createB(headA, n);
	struct N *p = headB->next;
	while(p!=NULL)
	{
		printf("%s ", p->s);
		p = p->next;
	}
	return 0;
}

你可能感兴趣的:(厦大实验题,链表,数据结构,c语言)