彩虹之巅style 2015-10-30 11:31 采纳率: 0%
浏览 1292

写了一个约瑟夫环,程序有一点问题一直改不了,希望大神指点一下

#include
#include
using namespace std;

template //type表示整型
class person
{
private:
string name;
type number;
string gender;
type age;
string classRoom;
string health;
person *next;
public:
person(string _name,type _number,string _gender,type _age,string _classRoom,string _health)
{
name=_name;
number=_number;
gender=_gender;
age=_age;
classRoom=_classRoom;
health=_health;
};
person(person *_next=NULL)
{
next=_next;
}
};

template
class personList
{
private:
int length;
person *head,*current;
public:
personList()
{
head=new person;
current=head;
}
~personList()
{
for(int i=0;i<getLength(length);i++)
delete head;
delete current;
head=NULL;
current=NULL;
}

bool IsEmpty()
{
 if(current->next==current)
    return true;
 else
    return false;
}

int getLength(int m)
{
    return m;
}
void addList(int m,person<type> & p)
{
    for(int i=0;i<m;i++)
    {
        current=current->next;
    }
    current->next=head;
}
void sortList(int m,int n)
{
    int count=0;
    for(int i=0;i<m;i++)
        for(int j=0;j<n;j++)
    {
        while(!IsEmpty())
    {
       current=current->next;
       person<type> *temporary=new person<type>;
       temporary=current;
       ++count;
       if(count==n-1)
       {
           cout<<"\n";
           cout<<temporary->name<<" "<<temporary->number<<" "<<temporary->gender<<" "<<temporary->age<<" ";
           cout<<temporary->classRoom<<" "<<temporary->health<<endl;
           delete temporary;
       }
       current->next=current->next->next;
    }

    }
    count=0;
}

};
int main()
{
person *every=new person;
personList pList=new personList;
int m,n;
cin>>m>>n;

string name;
int number;
string gender;
int age;
string classRoom;
string health;

for(int i=0;i<m;i++)
{
    cin>>name>>number>>gender>>age>>classRoom>>health;
    every[i]=new person<int>(name,number,gender,age,classRoom,health);
    pList->addList(&m,every[i]);
}

pList.sortList(&m,&n);
getLength(&m);
return 0;

}

  • 写回答

2条回答 默认 最新

  • devmiao 2015-10-30 13:00
    关注

    代码太多,就不看了,觉得可能是指针的问题

    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料