匿名用户
1级
2012-11-12 回答
// 实现下面三个函数实现将一个链表中的26个英文字母由小写变为大写,并各自输出。
//------------
//CreateList() 创建一个链表纪录26个小写的英文字母
//ListTransfer() 将链表中个各个节点有小写变为大写
//Listprint() 输入链表
//------------
# include
# include
typedef struct A
{
char c;
struct A *pnext;
}YW,*PYW;
PYW CreateList()
{
int i=0;
PYW head=NULL,pnew=NULL,pwei=NULL;
head = (PYW)malloc(sizeof(YW));
if(!head)
{
printf("内存分配失败!!!\n");
exit(0);
}
head->c = 0;
head->pnext = NULL;
pwei = head;
for(i='a';i
{
pnew = (PYW)malloc(sizeof(YW));
if(!pnew)
{
printf("内存分配失败!!!\n");
exit(0);
}
pnew->c = i;
pnew->pnext = NULL;
pwei->pnext = pnew;
pwei = pnew;
}
return head;
}
void ListTransfer(PYW head)
{
PYW p = head->pnext;
while(p)
{
p->c -= 32;
p = p->pnext;
}
return;
}
void ListPrint(PYW head)
{
PYW p = head->pnext;
while(p)
{
printf("%c ",p->c);
p = p->pnext;
}
return;
}
int main(void)
{
PYW p = NULL;
p = CreateList();
ListPrint(p);
printf("\n");
ListTransfer(p);
ListPrint(p);
printf("\n");
return 0;
}