更多"第48~50题基于以下信息。以下程序的功能是:建立一个带有头结点的单向"的相关试题:
[单项选择]第48~50题基于以下信息。以下程序的功能是:建立一个带有头结点的单向链表,并将存储在数组中的字符依次转储到链表的各个结点中,请从与下划线处号码对应的一组选若中选择出正确的选项。
#include
stuct node
{ char data; struct node *next;};
(48) CreatList(char *s)
{ struct node *h,*p,*q);
h=(struct node *)malloc(sizeof(struct node));
p=q=h;
while(*s!=’/0’)
{ p=(struct node *)malloc(sizeof(struct node));
p->data= (49) ;
q->next=p;
q= (50) ; s++;
}
p->next=’/0’;
return h;
}
main( )
{ char str[ ]="link list";
struct node *head;
head=CreatList(str);
...
}
A. char *
B. struct node
C. struct node*
D. char
[简答题]【说明】
以下程序的功能是设计一个栈类stack<T>,并建立一个整数栈。
【程序】
#include < iostream. h >
#include < stdlib. h >
const int Max =20; //栈大小
template < class T >
class stack{ //栈元素数组
T s[Max]; //栈顶下标
int top;
public:
stack( )
{
top =-1; //栈顶初始化为-1
}
void push( const T &item); //item入栈
T pop( ); //出栈
int stackempty( ) const; //判断栈是否为
};
template < class T >
void stack <T >::push(const T &item)
{
if(top== (1) )
{
cout <<"栈满溢出" <<endl;
exit(1);
}
top ++
s[top] = item;
}
template < class T >
T stack<T> ::pop( )
{
T temp;
if(top== (2) )
{
cout <<"栈为空,不能出栈操作" < < endl;
exit(1);
}
temp =s[top];
top --;
return temp;
}
template < class T >
int stack < T >:: stackempty( ) const
{ return top == -1;
{
void main( )
{
stack <int> st;
int a[] ={1,2,3,4,5};
cout <<"整数栈" <<e
[简答题]【说明】
以下程序的功能是设计一个栈类stack<T>,并建立一个整数栈。
【程序】
#include < iostream. h >
#include < stdlib. h >
const int Max =20; //栈大小
template < class T >
class stack //栈元素数组
T s[Max]; //栈顶下标
int top;
public:
stack( )
top =-1; //栈顶初始化为-1
void push( const T &item); //item入栈
T pop( ); //出栈
int stackempty( ) const; //判断栈是否为
;
template < class T >
void stack <T >::push(const T &item)
if(top== (1) )
cout <<"栈满溢出" <<endl;
exit(1);
top ++
s[top] = item;
template < class T >
T stack<T> ::pop( )
T temp;
if(top== (2) )
cout <<"栈为空,不能出栈操作" < < endl;
exit(1);
temp =s[top];
top --;
return temp;
template < class T >
int stack < T >:: stackempty( )
[填空题]以下程序的功能是建立一个带有头结点的单向链表,链表结点中的数据通过键盘输入,当输入数据为-1时,表示输入结束(链表头结点的data域不放数据,表空的条件是ph->next==NULL),请填空。
#include <stdio.h>
struct list int data;struct list *next;;
struct list *creatlist( )
struct list *p,*q,*ph;int a;ph=(struct list*)malloc(sizeof(struct list));
p=q=ph;printf("Input an integer number;entre-1 to end:/n");
scanf("%d",&a);
while(a!=-1)
p=(struct list*)malloc(sizeof(struct list));
______=a;q->next=p;______=p;scanf("%d",&a);
p->next=’/0’;return(ph);
main( )
stuct list * head;head=creatlist( );
[简答题]系统功能语法的建立基于以下两个事实:
(1)语言的使用者实际上是在一组系统中进行选择,并且努力在社会的相互作用中实现不同的语义功能;
(2)语言在人类的社会活动紧密联系,不可分离。
请就此进行简评并讨论系统功能语法与乔姆斯的转换生成语法的主要区别。
[填空题]以下程序的功能是建立—个带有头结点的单向链表,链表结点中的数据通过键盘输入,当输入数据为-1时,表示输入结束(链表头结点的data域不放数据,表空的条件是ph->next==NULL),请填空。
#include<stdio.h>
struct list { int data;struct list *next;};
struct list * creatlist( )
{ struct list *p,*q,*ph;int a;ph=(struct list *)malloc(sizeof(struct list));
p=q=ph;printf("Input an integer number;entre-1 to end:/n");
scanf("%d",&a);
while(a!=-1)
{ p=(struct list*)malloc(sizeof(struct list));
[14] =a;q->next=p; [15] =p;scanf("%d",&a);}
p->next=’/0’;return(ph);}
main( )
{stuct list * head;head=creatlist( );}
[单项选择](48)~(50)题以下程序的功能是:建立一个带布头结点的单向链表,并将存储在数组中的字符依次存储到链表的各个结点中,请从与下划线处号码对应的一组选项中选择出正确的选项
#include <stdlib.h>
struct node
{char data; struct node *next;};
(48) CreatList(char*s),
{struct node *h,*p,*q;
h=(struct node*)malloc(sizeof(struct node));
p=q=h;
while(*s!="/0")
{ p=(struct node*)malloc(sizeof(struct node));
p->data= (49) ;
q->next=p;
q= (50) ;
s++;
}
p->next="/0";
return h;
}
main( )
{ char str[]="link list";
struct node*head;
head=CreatList(str);
…
}
A. char*
B. struct node
C. struct node*
D. char
[单项选择]以下程序的功能是:建立一个带有头结点的单向链表,并将存储在数组中的字符依次转存到链表的各个结点中,请填空。
#include <stdlib.h>
stuct node
char data; struet node * next; ;
stntct node * CreatList(char * s)
struet node *h,*p,*q;
h = (struct node * ) malloc(sizeof(struct node) );
p=q=h;
while( * s! =’/0’)
p = (struct node *) malloc ( sizeof(struct node) );
p - > data = ( )
q- >next=p;
q=p;
a++;
p- > next =’/0’;
return h;
main( )
char str[ ]= "link list";
struet node * head;
head = CreatList(str);
A. *s
B. s
C. *s++
D. (*s)++
[单项选择]
以下程序的功能是:建立一个带有头结点的单向链表,并将存储在数组中的字符依次转储到链表的各个结点中,请从与下划线处号码对应的一组选若中选择出正确的选项。#include
stuct node{ char data; struct node *next;}; (1) CreatLis(char *s){
struct node *h,*p,*q); h=(struct node *)malloc(sizeof(struct node));
p=q=h; while(*s!=’/0’) { p=(struct node
*)malloc(sizeof(struct node)); p->data= (2) ;
q->next=p; q= (3) ; s++; }
p->next=’/0’; return h;}main( ){ char str[]="link list";
struct node *head; head=CreatLis(str); ...}
2()
A. *s
B. s
C. *s++
D. (*++