输入一个字符串,将其中的字母字符输入一个链表,将其中的数字字符输入另一个链表,要求程序能够按读入时相反顺序输出两个字符串。
知道用伪代码怎么实现,但是无法编出可以运行的代码,求大佬帮助。
// Q753292.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
struct node
{
char v;
node * next;
};
node * create()
{
node * r = (node *)malloc(sizeof(node));
r->v = '\0';
r->next = NULL;
return r;
}
void append(node * head, char ch)
{
node * curr = head;
while (curr->next != NULL) curr = curr->next;
curr->next = (node *)malloc(sizeof(node));
curr->next->v = ch;
curr->next->next = NULL;
}
void printlist(node * head)
{
node * curr = head;
while (curr->next != NULL)
{
curr = curr->next;
printf("%c ", curr->v);
}
printf("\n");
}
int main()
{
char input[100];
scanf("%s", &input);
node * wl = create();
node * nl = create();
for (int i = 0; i < strlen(input); i++)
{
if (input[i] >= 'a' && input[i] <= 'z')
append(wl, input[i]);
if (input[i] >= 'A' && input[i] <= 'Z')
append(wl, input[i]);
if (input[i] >= '0' && input[i] <= '9')
append(nl, input[i]);
}
printf("letters:");
printlist(wl);
printf("numbers:");
printlist(nl);
return 0;
}