qq_25005337 2015-04-28 14:50 采纳率: 0%
浏览 1499

求大神帮助解释这段C语言代码

*/
#include
#include
using namespace std;

//////////////////////////////
//
template class List;

/*结点*/
template
class Node
{

friend class List;
T value;
Node *next;
Node(int v,Node *n)
{
value=v,next=n;
}
};

///////////////////////////////
//
/*链表*/
template
class List
{
public:
List();
~List();
void showList();
void xunhuan();
void shanchu(Node *p);
void js(int n,int s,int m);
bool isEmpty()
{
return head==NULL;
};
void append(const T value);
private:
Node *head;
};

template
void List::showList()
{
Node *p=head;
while(p!=NULL)
{
cout<value<<' ';
p=p->next;
}
}

template
List::List()
{
head=NULL;
}

template
List::~List()
{}

template
void List::append(T v)
{
Node *e=new Node(v,NULL);
Node *p=head;
if(head==NULL)
{

head=e;

}
else
{
while(p->next!=NULL)
p=p->next;
p->next=e;
}
}

template
void List::xunhuan()
{
Node *p=head;
while(p->next!=NULL)
{
p=p->next;
}
p->next=head;

}

template
void List::shanchu(Node *p)
{
Node *h=p;

while(h->next!=p)
    h=h->next;
h->next=p->next;
delete p;

}

template
void List::js(int n,int s,int m)
{
Node *p=head;
Node *temp;
int i;

for(i=0;i<s-1;i++)
    p=p->next;

cout<<"出列顺序为:";
while(n!=1)
{  

    for(i=0;i<m-1;i++)
        p=p->next;


    cout<<p->value<<' ';
    temp=p;
    p=p->next;
    shanchu(temp);


    n--;
}


cout<<p->value;

}

////////////////////////////////////////
//
class Text
{
public:
void text()
{
/*
n为单链表的长度;
s为从开头第S个结点处开始报数
m为报数长度,报m的结点将被删除
*/
List list;
int i;
int n,s,m;

    cout<<"请输入n,s,m三个相关数据"<<endl;
    cin>>n>>s>>m;


    for(i=0;i<n;i++)
        list.append(i+1);


    list.showList();
    cout<<endl;


    list.xunhuan();


    list.js(n,s,m);
}

};
/////////////////////////////////////////////////////////////
//主函数
int main()
{
Text t;
t.text();
while(1){}
return 0;
}

  • 写回答

3条回答 默认 最新

  • threenewbee 2015-04-28 14:53
    关注

    这不是C语言,是C++,用到了模板,定义了链表,夹杂着英文和拼音,你可以看出是干嘛的
    比如 shanchu 删除
    append 追加
    等等

    具体什么不懂,请贴出来。

    评论

报告相同问题?

悬赏问题

  • ¥15 opencv 无法读取视频
  • ¥15 用matlab 实现通信仿真
  • ¥15 按键修改电子时钟,C51单片机
  • ¥60 Java中实现如何实现张量类,并用于图像处理(不运用其他科学计算库和图像处理库))
  • ¥20 5037端口被adb自己占了
  • ¥15 python:excel数据写入多个对应word文档
  • ¥60 全一数分解素因子和素数循环节位数
  • ¥15 ffmpeg如何安装到虚拟环境
  • ¥188 寻找能做王者评分提取的
  • ¥15 matlab用simulink求解一个二阶微分方程,要求截图