本文目錄一覽:
- 1、用c語言設計線性順序表,求前驅,後進的問題。
- 2、字母前驅後驅c語言怎麼表示
- 3、C語言的前驅後繼問題
- 4、C語言中的前趨結點是什麼
- 5、C語言:求前驅和後繼字母。輸入一個大寫字母,求對應的小寫字母及它的前驅和後繼
- 6、C語言中前驅後繼字符是什麼?下面程序怎麼寫
用c語言設計線性順序表,求前驅,後進的問題。
下面是我該完的程序。請運行一下,我改的地方都加了注釋」//這裡修改了「
#include stdio.h
#define OK 1
#define ERROR 0
#define TRUE 1
#define FALSE 0
#define OVERFLOW -2
#define MAXSIZE 100
typedef int status;
typedef int elemtype;
typedef struct {
elemtype elem[MAXSIZE];
int length;
}sqlist;
/*初始化*/
status initlist(sqlist *l){
l-length=0;
return OK;
}
/*銷毀*/
status destroylist(sqlist *l){
l-length=0;
return OK;
}
/*順序表置空*/
status clearlist(sqlist *l){
l-length=0;
return OK;
}
/*求順序表長度*/
int listlength(sqlist l){
return l.length;
}
/*順序表空否*/
status listempty(sqlist l){
if( l.length) return FALSE;
else return TRUE;
}
/*查找*/
int locateelem(sqlist l,elemtype e){
int i=0;
while(il.length)
if (l.elem[i++]==e) return i;
return 0;
}
/*讀第i個元素*/
status getelem(sqlist l,int i,elemtype *e){
if((i1)||(il.length)) return ERROR;
*e=l.elem[i-1];
return OK;
}
/*求前驅*/
status priorelem(sqlist l,elemtype cur_e,elemtype *pre_e){
int i;
i=locateelem(l,cur_e);
if((i==0)||(i==1)) {*pre_e=’no’;printf(” 沒有前驅 “);;return ERROR;} //這裡修改了
else //這裡修改了
{
*pre_e=l.elem[i-2];
return OK;
}
}
/*求後繼*/
status nextelem(sqlist l,elemtype cur_e,elemtype *next_e){
int i;
i=locateelem(l,cur_e);
if((i==0)||(i==l.length)){ *next_e=’no’;printf(” 沒有後繼 “);return ERROR;} //這裡修改了
else //這裡修改了
{
*next_e=l.elem[i];
return OK;
}
}
/*在第i個位置插入元素e*/
status listinsert(sqlist *l,int i,elemtype e){
int j;
if((i1)||(il-length+1)) return ERROR;
for(j=l-length;ji-1;j–) l-elem[j]=l-elem[j-1];
l-elem[i-1]=e;
l-length++;
return OK;
}
/*刪除第i個元素*/
status listdelete(sqlist *l,int i,elemtype *e){
int j;
if((i1)||(il-length)) return ERROR;
*e=l-elem[i-1];
for(j= i;j l-length;j++) l-elem[j-1]=l-elem[j];
l-length–;
return OK;
}
/*遍歷*/
status listtraverse(sqlist l){
int i;
for(i=1;i=l.length;i++)
printf(“%d “,l.elem[i-1]);
printf(“\n”);
return OK;
}
/*建立順序表*/
status listcreate(sqlist *l){
int i=0;
elemtype e;
printf(“input data(end by -1):”);
scanf(“%d”,e);
while(e!=-1){
l-elem[i++]=e;
scanf(“%d”,e);
}
l-length=i;
return OK;
}
/*主函數*/
main(){
sqlist la,lb,lc;
int i;
elemtype e,pre_e,next_e;
listcreate(la);
listtraverse(la);
printf(“the length of the list is %d\n”,listlength(la));
printf(“input i and e for insert:”);
scanf(“%d %d”,i,e);
if(listinsert(la,i,e)) listtraverse(la);
else printf(“i is error!\n”);
printf(“input i :”);
scanf(“%d”,i);
getelem(la,i,e);
printf(“the element is %d ,”,e);
priorelem(la,e,pre_e);
nextelem(la,e,next_e);
if(pre_e!=’no’)printf(“the priore is %d\n”,pre_e); //這裡修改了
if(next_e!=’no’)printf(“the next is %d\n”,next_e); //這裡修改了
listdelete(la,i,e);
listtraverse(la);
}
字母前驅後驅c語言怎麼表示
在C語言中
字符的直接前驅:’b’-1
字符的直接後繼:’b’+1
注意輸出的時候用控制符%c,比如
printf(‘%c’,’b’-1);
C語言的前驅後繼問題
#include stdio.h
void main()
{
char c1, c2, c3;
printf(“input a letter\n”);
scanf(“%c”,c1);
c2 = c1 – 1;
c3 = c1 + 1;
if (c1 == ‘a’)
c2 = ‘z’;
if (c1 == ‘z’)
c3 = ‘a’;
printf(“%c,%c\n”,c2,c3);
}
不謝
C語言中的前趨結點是什麼
前驅結點是線性表或鏈表等數據存儲結構中的一個概念,當前結點的前一個結點稱為直接前驅結點。
舉例說明如下:
1、對於線性表存儲結構:
1, 2, 3, 4, 5, ……, k, k+1, …….
則結點k+1的直接前驅結點為結點k
2、對於鏈表存儲結構
// 結點的定義
struct node
{
int data; // 數據域
struct node *next; // 指針域
};
struct node *Head; // Head表示鏈表的頭結點,則Head-next為頭結點Head的後繼結點;Head為Head-next的前驅節點
C語言:求前驅和後繼字母。輸入一個大寫字母,求對應的小寫字母及它的前驅和後繼
樓主你好。
#includestdio.h
int main()
{
char ch,ch1,ch2;
scanf(“%c”,ch);
if(ch=’B’ch=’Y’){
ch1=ch+31;
ch2=ch+33;
}else if(ch==’A’){
ch1=’-‘;
ch2=ch+33;
}else {
ch1=ch+31;
ch2=’-‘;
}
printf(“%c %c\n”,ch1,ch2);
return 0;
}
ch,ch1,ch2應該聲明為char類型。
你原先定義成為int類型會導致條件判斷的時候總是進入最後一個else中。所以只有前驅,沒有後繼。
C語言中前驅後繼字符是什麼?下面程序怎麼寫
前驅就是前面的字符,比如b的前驅就是a,後繼是一樣的,那無非就是強制轉化,讀一個char ,強製為int,輸出的就是它的碼,讓char加一就是後繼,減一就是前驅
原創文章,作者:BFAD,如若轉載,請註明出處:https://www.506064.com/zh-hk/n/131552.html