问题描述:线性表循环右移k位,即:
1 2 3 4 5 6 7 8 9
右移3位后
6 7 8 9 1 2 3 4 5
#include <iostream>
#include <cstdlib>
using namespace std;
typedef int elemtype;
typedef struct{
elemtype* elem;
int listsize;
int length;
}sqlist;
void create_L(sqlist& L){
L.elem=(elemtype*)malloc(1000*sizeof(elemtype));
L.listsize=1000;
L.length=0;
}
void show(sqlist& L){
for(int i=0;i<L.length;i++){
cout<<L.elem[i]<<" ";
}
cout<<endl;
}
#include <iostream>
#include <cstdlib>
using namespace std;
typedef int elemtype;
typedef struct{
elemtype* elem;
int listsize;
int length;
}sqlist;
void create_L(sqlist& L){
L.elem=(elemtype*)malloc(1000*sizeof(elemtype));
L.listsize=1000;
L.length=0;
}
void show(sqlist& L){
for(int i=0;i<L.length;i++){
cout<<L.elem[i]<<" ";
}
cout<<endl;
}

本文探讨了线性表数据结构中如何实现循环右移k位的操作,详细解析了算法步骤,包括如何处理不同长度的线性表以及k值的边界条件,旨在帮助读者理解线性表的动态调整和数据移动的逻辑。
最低0.47元/天 解锁文章
630

被折叠的 条评论
为什么被折叠?



