创建两个链表 - 一个存储大写字符,另一个存储小写字符。 [英] Create two linked lists—one which stores upper case characters and the other that stores lower case characters.
本文介绍了创建两个链表 - 一个存储大写字符,另一个存储小写字符。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我无法理解在找到大写字母后如何将其存储到另一个链表中?
我尝试过的方法:
#include< stdio.h>
#include< stdlib.h>
struct node
{
char info [30];
struct node * next;
};
struct node * start;
void create()
{char ch ='y';
struct node * temp,* ptr;
while(ch!='n')
{
temp =(struct node *)malloc(sizeof(struct node));
printf(\ n输入节点数据:\ n);
scanf(%s,& temp-> info);
temp-> next = NULL;
if(start == NULL)
{
start = temp;
}
其他
{
ptr = start;
while(ptr-> next!= NULL)
{
ptr = ptr-> next;
}
ptr-> next = temp;
}
printf(\ n你想继续:\ n);
ch = getch();
}
}
void display()
{
struct node * ptr;
if(start == NULL)
{
printf(\ n list is empty \\\
);
}
其他
{
ptr = start;
while(ptr!= NULL)
{
printf(%s \ t,ptr-> info);
ptr = ptr-> next;
}
}
}
void uppercase()
{
struct node * ptr,* temp,* ptr1;
temp =(struct node *)malloc(sizeof(struct node));
temp-> next = NULL;
ptr = start;
while(ptr-> next!= NULL)
{
ptr = ptr-> next;
if(ptr-> info> ='A'&& ptr-> info< ='Z')
{
temp = ptr-> info;
ptr1 = temp;
}
ptr1-> next = temp-> next;
}
}
void main()
{
create();
display();
uppercase();
display();
}
解决方案
逻辑很简单:
NodeAdd(node * List,Char Characgter)
{
//将新字符添加到列表中的代码
}
int main()
{
struct node * UpperList;
struct node * LowerList;
allCharacters中的每个字符
{
如果字符是上限
NodeAdd(UpperList,character);
else
NodeAdd(LowerList,character);
}
}
#include< stdio.h>
#include< stdlib.h>
struct 节点
{
char info [ 30 跨度>];
struct node * next;
};
struct node * start;
void create()
{ char ch = ' y';
struct node * temp,* ptr;
while (ch!= ' n' )
{
temp =( struct node *)malloc( sizeof ( struct node));
printf( \ n输入节点数据:\ n);
scanf( %s,& temp-> info);
temp-> next = NULL;
if (start == NULL)
{
start = temp;
}
else
{
ptr = start;
while (ptr-> next!= NULL)
{
ptr = ptr-> next;
}
ptr-> next = temp;
}
printf( \ n是否要继续:\ n< /跨度>);
ch = getch();
}
}
void display()
{
struct node * ptr;
if (start == NULL)
{
printf( \ n list为空\ n);
}
else
{
ptr = start;
while (ptr!= NULL)
{
printf( %s \ t,ptr-> info);
ptr = ptr-> next;
}
}
}
void uppercase()
{
struct node * ptr,* temp,* ptr1;
temp =( struct node *)malloc( sizeof ( struct node));
temp-> next = NULL;
ptr = start;
while (ptr-> next!= NULL)
{
ptr = ptr-> next;
if (ptr-> info> = ' A'&& ptr-> info< = ' Z')
{
temp = ptr-> info;
ptr1 = temp;
}
ptr1-> next = temp-> next;
}
}
void main()
{
create();
display();
uppercase();
// display();
}
I am not able to understand that after finding out uppercase letters how will i store it into another linked list?
What I have tried:
# include <stdio.h> # include <stdlib.h> struct node { char info[30]; struct node *next; }; struct node *start; void create() { char ch='y'; struct node *temp,*ptr; while(ch!='n') { temp=(struct node *)malloc(sizeof(struct node)); printf("\n enter the node data: \n"); scanf("%s",&temp->info); temp->next=NULL; if(start==NULL) { start=temp; } else { ptr=start; while(ptr->next!=NULL) { ptr=ptr->next; } ptr->next=temp; } printf("\n Do you want to continue: \n"); ch=getch(); } } void display() { struct node *ptr; if(start==NULL) { printf("\n list is empty \n"); } else { ptr=start; while(ptr!=NULL) { printf("%s\t",ptr->info); ptr=ptr->next; } } } void uppercase() { struct node *ptr,*temp,*ptr1; temp=(struct node *)malloc(sizeof(struct node)); temp->next=NULL; ptr=start; while(ptr->next!=NULL) { ptr=ptr->next; if(ptr->info >='A' && ptr->info <= 'Z') { temp=ptr->info; ptr1=temp; } ptr1->next=temp->next; } } void main() { create(); display(); uppercase(); display(); }
解决方案
The logic is quite straightforward:
NodeAdd(node* List, Char Characgter) { // code to add a new character to a list } int main() { struct node* UpperList; struct node* LowerList; for each character in allCharacters { if character is upper NodeAdd(UpperList, character); else NodeAdd(LowerList, character); } }
# include <stdio.h> # include <stdlib.h> struct node { char info[30]; struct node *next; }; struct node *start; void create() { char ch='y'; struct node *temp,*ptr; while(ch!='n') { temp=(struct node *)malloc(sizeof(struct node)); printf("\n enter the node data: \n"); scanf("%s",&temp->info); temp->next=NULL; if(start==NULL) { start=temp; } else { ptr=start; while(ptr->next!=NULL) { ptr=ptr->next; } ptr->next=temp; } printf("\n Do you want to continue: \n"); ch=getch(); } } void display() { struct node *ptr; if(start==NULL) { printf("\n list is empty \n"); } else { ptr=start; while(ptr!=NULL) { printf("%s\t",ptr->info); ptr=ptr->next; } } } void uppercase() { struct node *ptr,*temp,*ptr1; temp=(struct node *)malloc(sizeof(struct node)); temp->next=NULL; ptr=start; while(ptr->next!=NULL) { ptr=ptr->next; if(ptr->info >='A' && ptr->info <= 'Z') { temp=ptr->info; ptr1=temp; } ptr1->next=temp->next; } } void main() { create(); display(); uppercase(); //display(); }
这篇关于创建两个链表 - 一个存储大写字符,另一个存储小写字符。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文