下面程序实现十进制向其他进制的转换。
[Java程序]
C1ass Node{
int data;
Node next;
}
class Transform{
private Node top;
publiC void print(){
Node P;
while(top !=null){
P=top;
if(P.data>9)
System.out.print((char)(p.data+55));
else
System.out.print(p.data);
top=P.next;
}
}
public void Trans(int d,int i)(//d为数字;i为进制
int m;
(1) n=false;
Node P;
while(d>0){
(2) ;
d=d/i;
P=flew Node();
if( (3) ){
P.data=m;
(4) ;
top=P;
n=true;
}
else{
p.data=m;
(5) ;
toP=P;
}
}
}
}
第1题:
阅读以下说明和C++程序,将应填入(n)处的字句写在对应栏内。
[说明]
下面程序实现十进制向其它进制的转换。
[C++程序]
include"ioStream.h"
include"math.h"
include
typedef struct node {
int data;
node*next;
}Node;
Class Transform.
{
DUDlic:
void Trans(int d,int i); //d为数字;i为进制
void print();
private:
Node*top;
};
void Transform.:Trans(int d,int i)
{
int m,n=0;
Node*P;
while(d>0)
{
(1);
d=d/i;
p=new Node;
if(!n){
p->data=m;
(2);
(3);
n++;
}
else{
p->data=m;
(4);
(5);
}
}
}
void Transform.:print()
{
Node*P;
while(top!=NULL)
{
p=top;
if(p->data>9)
cout<<data+55;
else
cout<<data;
top=p->next;
delete p;
}
}
第2题:
下列给定程序中,是建立一个带头结点的单向链表,并用随机函数为各结点数据域赋值。函数fun的作用是求出单向链表结点(不包括头结点)数据域中的最大值,并且作为函数值返回。
请改正程序指定部位的错误,使它能得到正确结果。
[注意] 不要改动main函数,不得增行或删行,也不得更改程序的结构。
[试题源程序]
include<stdio.h>
include<stdlib.h>
typedef struct aa
{
int data;
struct aa *next;
}NODE;
fun(NODE *h)
{
int max=-1;
NODE *p;
/***********found************/
p=h;
while(p)
{
if(p->data>max)
max=p->data;
/************found************/
p=h->next;
}
return max;
}
outresult(int s, FILE *Pf)
{
fprintf(pf, "\nThe max in link: %d\n", s);
}
NODE *creatlink(int n, int m)
{
NODE *h, *p, *s, *q;
int i, x;
h=p=(NODE *)malloc(sizeof(NODE));
h->data=9999;
for(i=1; i<=n; i++)
{
s=(NODE *)malloc(sizeof(NODE));
s->data=rand()%m; s->next=p->next;
p->next=s; p=p->next;
}
p->next=NULL;
return h;
}
outlink(NODE *h, FILE *pf)
{
NODE *p;
p=h->next;
fprintf(Pf, "\nTHE LIST:\n\n HEAD");
while(P)
{
fprintf(pf, "->%d", P->datA); p=p->next;
}
fprintf(pf, "\n");
}
main()
{
NODE *head; int m;
head=cteatlink(12,100);
outlink(head, stdout);
m=fun(head);
printf("\nTHE RESULT"\n");
outresult(m, stdout);
}
第3题:
为了建立如图所示存储结果,data为数据区,next为指向结点的指针域,请填空: data next struct link { char data; ; }node;
第4题:
阅读以下说明和Java程序,将应填入(n)处的字句写在对应栏内。
[说明]
下面程序实现十进制向其它进制的转换。
[Java程序]
ClasS Node{
int data;
Node next;
}
class Transform{
private Node top;
public void print(){
Node p;
while(top!=null){
P=top;
if(P.data>9)
System.out.print((char)(P.data+55));
else
System.out.print(p.data);
top=p.next;
}
}
public void Trans(int d,int i){//d为数字;i为进制
int m;
(1) n=false;
Node p;
while(d>0){
(2);
d=d/i;
p=new Node();
if( (3) ){
p.data=m;
(4);
top=P;
n=true;
}
else{
p.data=m;
(5);
top=P;
}
}
}
}
第5题:
下而程序实现十进制向其他进制的转换。
[C++程序]
include"ioStream.h"
include"math.h"
include <conio.h>
typedef struct node{
int data;
node *next;
}Node;
class Transform
{
public:
void Trans(int d,int i); //d为数字;i为进制
void print();
private:
Node *top;
};
void Transform.:Trans(int d,int i)
{
int m,n=0;
Node *P;
while(d>0)
{
(1) ;
d=d/i;
p=new Node;
if(!n){
P->data=m;
(2) j
(3) ;
n++;
}
else{
p->data=m;
(4) ;
(5) ;
}
}
}
void Transform.:print()
{
Node *P;
while(top!=NULL)
{
p=top;
if(P->data>9)
cout<<data+55:
else
cout<<data;
top=p->next;
delete P;
}
}