6-3 顺序表的删除操作 (10 分)
本文最后更新于1488天前,其中的信息可能已经有所发展或是发生改变。

本题要求实现一个函数,要求将顺序表的第i个元素删掉,成功删除返回1,否则返回0;

函数接口定义:

int ListDelete(SqList &L,int i);

其中SqList结构定义如下:

typedef struct{
	ElemType *elem;
	int length;
 }SqList;

裁判测试程序样例:

#include <stdio.h>
#include <stdlib.h>
#define MAXSIZE 5
typedef int ElemType;
typedef struct{
	ElemType *elem;
	int length;
 }SqList;
void InitList(SqList &L);/*细节在此不表*/
int ListDelete(SqList &L,int i);
int main()
{
	SqList L;
	InitList(L);
	int i;
	scanf("%d",&i);
	int result=ListDelete(L,i);
	if(result==0){
		printf("Delete Error.The value of i is illegal!");	
	}else if(result==1){
		printf("Delete Success.The elements of the SequenceList L are:");	
		for(int j=0;j<L.length;j++){
			printf(" %d",L.elem[j]);
		}
	}
	return 0;
}
/* 请在这里填写答案 */

输入格式:

输入数据有1行,首先给出以-1结束的顺序表元素值(不超过100个,-1不属于顺序表元素),然后是删除位置。所有数据之间用空格分隔。

输入样例:

2 6 4 -1 1

输出样例:

Delete Success.The elements of the SequenceList L are: 6 4
int ListDelete(SqList &L,int i)
{
    int j;

    if(i<1||i>L.length) return 0;
    for(j = i;j < L.length;j++)
    {
        L.elem[j-1] = L.elem[j]; // 依次左移
    }
    L.length--;
    return 1;
}

 

点击数:661

暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇