刚开始学数据结构和算法 出现了以下有关问题 下面是代码 求大大们帮忙
刚开始学数据结构和算法 出现了以下问题 下面是代码 求大大们帮忙
#pragma once
#include "list.h"
using namespace std;
#include<iostream>
template<class T>
class arrList :
public List<T>
{
private:
T *alist;
int maxSize;
int curlen;
int position;
public:
arrList(const int size){
maxSize=size;
alist=new T[maxSize];
curlen=position=0;
}
~arrList(){
delete [] alist;
}
void clear(){
curlen=position=0;
}
// int length();
bool getValue(const int p,T& value);
bool insert(const int p,const T value);
};
#include "stdafx.h"
#include "arrList.h"
template <class T>
/*int arrList<int>::length()
{
return curlen;
}*/
bool arrList<T>::insert(const int p,const T value)
{
int i;
if(curlen>=maxSize)
{
cout<<"overflow"<<endl;
return false;
}
if(p<0||p>curlen)
{
cout<<"illegal"<<endl;
return false;
}
for(i=curlen;i>p;i--)
alist[i]=alist[i-1];
alist[p]=value;
curlen++;
return true;
}
bool arrList<int>::getValue (const int p,int &value )
{
value=alist[p];
return true;
}
#pragma once
template <class T>
class List
{
public:
void clear();
bool isEmpty();
bool append(const T value);
bool insert(const int p,const T value );
bool Delete(const int p);
bool getValue(const int p,T&value);
bool setValue(const int p,const T value);
bool getPos(int &p,const T value);
};
#include "stdafx.h"
#include<iostream>
#include"arrList.h"
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int n,s,m,j;
cout<<"enter data n,s,m:"<<endl;
cin>>n>>s>>m;
arrList<int> a(n),b(n);
cout<<"enter n...:"<<endl;
for(int i=0;i<n;i++)
{
int x;
cin>>x;
a.insert(i,x);
}
for(int i=0;i<n;i++)
{
j=s-1;
for(j;j<s+m-1;j++)
{
if(j==n-1)
j=0;
}
if(j==n-1)
s=0;
else
s=j+1;
int value;
a.getValue(j,value);
b.insert(i,value);
}
for(int i=0;i<n;i++)
{
int value;
b.getValue(i,value);
cout<<value<<endl;
}
return 0;
}
------解决思路----------------------
arrList<T>的insert函数在那里
------解决思路----------------------
没有找到insert的实现
#pragma once
#include "list.h"
using namespace std;
#include<iostream>
template<class T>
class arrList :
public List<T>
{
private:
T *alist;
int maxSize;
int curlen;
int position;
public:
arrList(const int size){
maxSize=size;
alist=new T[maxSize];
curlen=position=0;
}
~arrList(){
delete [] alist;
}
void clear(){
curlen=position=0;
}
// int length();
bool getValue(const int p,T& value);
bool insert(const int p,const T value);
};
#include "stdafx.h"
#include "arrList.h"
template <class T>
/*int arrList<int>::length()
{
return curlen;
}*/
bool arrList<T>::insert(const int p,const T value)
{
int i;
if(curlen>=maxSize)
{
cout<<"overflow"<<endl;
return false;
}
if(p<0||p>curlen)
{
cout<<"illegal"<<endl;
return false;
}
for(i=curlen;i>p;i--)
alist[i]=alist[i-1];
alist[p]=value;
curlen++;
return true;
}
bool arrList<int>::getValue (const int p,int &value )
{
value=alist[p];
return true;
}
#pragma once
template <class T>
class List
{
public:
void clear();
bool isEmpty();
bool append(const T value);
bool insert(const int p,const T value );
bool Delete(const int p);
bool getValue(const int p,T&value);
bool setValue(const int p,const T value);
bool getPos(int &p,const T value);
};
#include "stdafx.h"
#include<iostream>
#include"arrList.h"
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int n,s,m,j;
cout<<"enter data n,s,m:"<<endl;
cin>>n>>s>>m;
arrList<int> a(n),b(n);
cout<<"enter n...:"<<endl;
for(int i=0;i<n;i++)
{
int x;
cin>>x;
a.insert(i,x);
}
for(int i=0;i<n;i++)
{
j=s-1;
for(j;j<s+m-1;j++)
{
if(j==n-1)
j=0;
}
if(j==n-1)
s=0;
else
s=j+1;
int value;
a.getValue(j,value);
b.insert(i,value);
}
for(int i=0;i<n;i++)
{
int value;
b.getValue(i,value);
cout<<value<<endl;
}
return 0;
}
------解决思路----------------------
arrList<T>的insert函数在那里
------解决思路----------------------
没有找到insert的实现