下面程序实现十进制向其他进制的转换。[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));elseSystem.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;}}}}

下面程序实现十进制向其他进制的转换。

[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;

}

}

}

}


相关考题:

以下程序实现栈的入栈和出栈的操作。其中有两个类:一个是节点类node,它包含点值和指向上一个节点的指针 prev;另一个类是栈类 stack, 它包含栈的头指针 top。生成的链式栈如下图所示。〈IMG nClick=over(this) title=放大 src="tp/jsj/2jc++j28.1.gif"〉下面是实现程序,请填空完成此程序。include 〈iostream〉using namespace std;class stack;class node{int data;node *prev;public:node(int d, node *n){data=d;prev=n;}friend class stack;};class stack{node *top; //栈头public:stack(){top=0;}void push(int i){node *n=【 】;top=n;}int pop(){node *t=top;if (top){top=top-〉prev;int c= t-〉data;delete t;return c;}return 0;}int main (){stack s;s.push(6);s.push(3);s.push (1);return 0;}

请补充函数fun(),该函数的功能是建立一个带头结点的单向链表并输出到文件“out98.dat”和屏幕上,各结点的值为对应的下标,链表的结点数及输出的文件名作为参数传入。注意:部分源程序给出如下。请勿改动主函数main 和其他函数中的任何内容,仪在函数fun()的横线上填入所编写的若干表达式或语句。试题程序:include<stdio. h>include<conio. h>include<stdlib. h>typedef struct ss{int data;struct ss *next;} NODE;void fun(int n,char*filename){NODE *h,*p, *s;FILE *pf;int i;h=p= (NODE *) malloc (sizeof (NODE));h->data=0;for (i=1; i {s=(NODE *)malloc (sizeof (NODE));s->data=【 】;【 】;p=【 】}p->next=NULL;if ( (pf=fopen (filename, "w") ) ==NULL){printf {"Can not open out9B.clat! ");exit (0);}p=h;fprintf (pf, "\n***THE LIST***\n");print f ("\n***THE LIST***\n")while (p){fprintf (pf, "%3d", p->data)printf ("%3d",p->data);if (p->next ! =NULL){fprintf (pf, "->");printf ("->");}p=p->next;}fprintf (pf, "\n");printf ("\n");fclose (pf);p=h;while (p){s=p;p=p->next;free (s);}}main(){char * filename="out98. dat";int n;clrscr ();printf (" \nInput n: ");scanf ("%d", n);fun (n, filename);}

阅读以下技术说明和Java代码,将Java程序中(1)~(5)空缺处的语句填写完整。[说明]类Queue表示队列,类中的方法如表4-12所示。类Node表示队列中的元素;类EmptyQueueException给出了队列中的异常处理操作。[Java代码]public class testmain { //主类public static viod main (string args[]) {Queue q= new Queue;q.enqueue("first!");q.enqueue("second!");q.enqueue("third!");(1) {while(true)system.out.println(q.dequeue());}catch( (2) ) { }}public class Queue { //队列node m_firstnode;public Queue(){m_firstnode=null;}public boolean isempty() {if (m_firstnode= =null)return true;elsereturn false;}public viod enqueue(object newnode) { //入队操作node next = m_firstnode;if (next = = null) m_firstnode=new node(newnode);else {while(next.getnext() !=null)next=next.getnext();next.setnext(new node(newnode));}}public object dequeue() (3) { //出队操作object node;if (is empty())(4)else {node =m_firstnode.getobject();m_firstnode=m_firstnode.getnext();return node;}}}public class node{ //队列中的元素object m_data;node m_next;public node(object data) {m_data=data; m_next=null;}public node(object data,node next) {m_data=data; m_next=next;}public void setobject(object data) {m_data=data; }public object getobject(object data) {return m_data; }public void setnext(node next) {m_next=next; }public node getnext() {return m_next; }}public class emptyqueueexception extends (5) { //异常处理类public emptyqueueexception() {system. out. println ( "队列已空!" );}}

阅读下列程序说明和C程序,已知其输出为“1 2 3 4 5 6 7 8 9 10”。将应填入(n)处的字句写在对应栏内。[说明]本程序包含的函数及其功能说明如下:(1)函数first_insert()的功能是在已知链表的首表元之前插入一个指定值的表元;(2)函数reverse_copy()的功能是按已知链表复制出一个新链表,但新链表的表元链接顺序与已知链表的表元链接顺序相反;(3)函数Print_link()用来输出链表中各表元的值;(4)函数free_link()用来释放链表全部表元空间。[程序]include <stdio. h >include <malloe. h >typodef struct node {int val;struct node * next;} NODE;void first_insert(NODE * * p,int v){ NODE *q = (NODE *) malloe(sizeof(NODE));q-val = v; q->next = *p; /* 为新表元赋值*/* p =(1); }NODE * reverse_copy( NODE * p){ NODE * u;for(u=NULL; p!=NULL; p=p->next) first_insert((2));return u;}void printlink(NODE * p ){ for(;(3)) prinff("%d\t", p-val);printf(" \n");}void free_link( NODE * p){ NODE * u;while(p! =NULL) { u=p-next;free(p);(4); }void main( ) { NODE * link1 , * link2;int i;link1 = NULL;for(i=1; i<= 10; i+ + )first_insert(linkl, i);link2 = reverse_copy(link1 );(5);free_link( linkl ) ;free_link(link2); }

阅读以下说明和C++程序,将应填入(n)处的字句写在对应栏内。[说明]下面程序实现十进制向其它进制的转换。[C++程序]include"ioStream.h"include"math.h"includetypedef 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;elsecout<<data;top=p->next;delete p;}}

阅读以下说明和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));elseSystem.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;}}}}

下列给定程序中,是建立一个带头结点的单向链表,并用随机函数为各结点数据域赋值。函数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);}

下而程序实现十进制向其他进制的转换。[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:elsecout<<data;top=p->next;delete P;}}

为了建立如图所示存储结果,data为数据区,next为指向结点的指针域,请填空: data next struct link { char data; ; }node;