c++问题帮我一下谢谢 5
12.Allocatean1-Darraywhichisfilledwithcapitalletters,charAlphabet[26]={‘A’,‘B’,‘C’,…,...
12. Allocate an 1-D array which is filled with capital letters,
char Alphabet[26] = {‘A’, ‘B’, ‘C’, … , ‘Z’}; .
And, declare a pointer array, Name, whose size is same as the length of your name.
Then make all of the elements of the Name point to appropriate element which has the same
letter composing your name. 展开
char Alphabet[26] = {‘A’, ‘B’, ‘C’, … , ‘Z’}; .
And, declare a pointer array, Name, whose size is same as the length of your name.
Then make all of the elements of the Name point to appropriate element which has the same
letter composing your name. 展开
2个回答
2011-04-01
展开全部
using namespace std;
#define true 1
#define false 0
typedef struct Node //定义一个队列
{
int data;
struct Node *next;
}LinkQueueNode;
typedef struct
{
LinkQueueNode *front;
LinkQueueNode *rear;
}LinkQueue;
void InitQueue(LinkQueue *Q) //初始化一个队列,把声明的队列的对象作为初始化的参数,不能用局部声明的变量
{
Q->front=Q->rear=(LinkQueueNode *)malloc(sizeof(LinkQueueNode));
Q->front->next=NULL;
}
void CreatQueue(LinkQueue *Q) //建立一个队列
{
int i,n;
LinkQueueNode *s;
cout<<"输入队列中的元素的个数n"<<endl;
cin>>n;
cout<<"输入队列中的元素"<<endl;
for(i=0;i<n;i++)
{
s=(LinkQueueNode*)malloc(sizeof(LinkQueueNode));//要分配空间
cin>>s->data;
Q->rear->next=s;
Q->rear=s;
//s=s->next; 无用
}
Q->rear->next=NULL;
}
int EnterQueue(LinkQueue *Q,int x) //入队操作
{
LinkQueueNode *NewNode;
NewNode=(LinkQueueNode*)malloc(sizeof(LinkQueueNode));
if(NewNode!=NULL)
{
NewNode->data=x;
NewNode->next=NULL;
Q->rear->next=NewNode;
Q->rear=NewNode;
return(true);
}
else
return(false);
}
void DeleteQueue(LinkQueue *Q) //出对操作
{
int data;
LinkQueueNode *p;
if(Q->front==Q->rear)
{
cout<<"队列为空"<<endl;
}
else
{
p=Q->front->next;
Q->front->next=p->next;
data=p->data;
free(p);
cout<<data<<endl;
}
}
void Output(LinkQueue *Q) // 输出队列中的值
{
LinkQueue *s;
s=Q;
LinkQueueNode *p;
p=s->front->next;
while(p!=NULL)
{
cout<<p->data<<" ";
p=p->next;
}
cout<<endl;
}
int main()
{
LinkQueue *Q=(LinkQueue*)malloc(sizeof(LinkQueue));
InitQueue(Q);
int aa=1,x;
while(aa)
{
cout<<"建队列请按1"<<endl;
cout<<"进队列请按2"<<endl;
cout<<"出队列请按3"<<endl;
cout<<"输出请按4"<<endl;
cout<<"退出请按0"<<endl;
cin>>aa;
switch(aa)
{
case 1:
CreatQueue(Q);
break;
case 2:
cout<<"输入进队列的值x"<<endl;
cin>>x;
EnterQueue(Q,x);
break;
case 3:
DeleteQueue(Q);
break;
case 4:
Output(Q);
break;
case 0:return(0);
break;
default:aa=0;
break;
}
}
return 0;
}
已经测试,没的问题
另外,站长团上有产品团购,便宜有保证
#define true 1
#define false 0
typedef struct Node //定义一个队列
{
int data;
struct Node *next;
}LinkQueueNode;
typedef struct
{
LinkQueueNode *front;
LinkQueueNode *rear;
}LinkQueue;
void InitQueue(LinkQueue *Q) //初始化一个队列,把声明的队列的对象作为初始化的参数,不能用局部声明的变量
{
Q->front=Q->rear=(LinkQueueNode *)malloc(sizeof(LinkQueueNode));
Q->front->next=NULL;
}
void CreatQueue(LinkQueue *Q) //建立一个队列
{
int i,n;
LinkQueueNode *s;
cout<<"输入队列中的元素的个数n"<<endl;
cin>>n;
cout<<"输入队列中的元素"<<endl;
for(i=0;i<n;i++)
{
s=(LinkQueueNode*)malloc(sizeof(LinkQueueNode));//要分配空间
cin>>s->data;
Q->rear->next=s;
Q->rear=s;
//s=s->next; 无用
}
Q->rear->next=NULL;
}
int EnterQueue(LinkQueue *Q,int x) //入队操作
{
LinkQueueNode *NewNode;
NewNode=(LinkQueueNode*)malloc(sizeof(LinkQueueNode));
if(NewNode!=NULL)
{
NewNode->data=x;
NewNode->next=NULL;
Q->rear->next=NewNode;
Q->rear=NewNode;
return(true);
}
else
return(false);
}
void DeleteQueue(LinkQueue *Q) //出对操作
{
int data;
LinkQueueNode *p;
if(Q->front==Q->rear)
{
cout<<"队列为空"<<endl;
}
else
{
p=Q->front->next;
Q->front->next=p->next;
data=p->data;
free(p);
cout<<data<<endl;
}
}
void Output(LinkQueue *Q) // 输出队列中的值
{
LinkQueue *s;
s=Q;
LinkQueueNode *p;
p=s->front->next;
while(p!=NULL)
{
cout<<p->data<<" ";
p=p->next;
}
cout<<endl;
}
int main()
{
LinkQueue *Q=(LinkQueue*)malloc(sizeof(LinkQueue));
InitQueue(Q);
int aa=1,x;
while(aa)
{
cout<<"建队列请按1"<<endl;
cout<<"进队列请按2"<<endl;
cout<<"出队列请按3"<<endl;
cout<<"输出请按4"<<endl;
cout<<"退出请按0"<<endl;
cin>>aa;
switch(aa)
{
case 1:
CreatQueue(Q);
break;
case 2:
cout<<"输入进队列的值x"<<endl;
cin>>x;
EnterQueue(Q,x);
break;
case 3:
DeleteQueue(Q);
break;
case 4:
Output(Q);
break;
case 0:return(0);
break;
default:aa=0;
break;
}
}
return 0;
}
已经测试,没的问题
另外,站长团上有产品团购,便宜有保证
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询