编辑代码

#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef struct Knodes{
    int data;
    struct Knodes *next;
}Knodes,*Lnodes;

void PtnLine();
Lnodes LinkInit();
int LinkPrt(Lnodes);
int LinkAdd(Lnodes,int);
int LinkDelSame(Lnodes,int,int);
int LinkVerPrt(Lnodes link1);
int LinkVer(Lnodes link1);
Lnodes LinkSGBCollect(Lnodes l1,Lnodes l2);
Lnodes LinkVer_DiGui(Lnodes link1);
Lnodes LinkSortGB(Lnodes link1);

int main() {
    Lnodes link1 = LinkInit();
    link1->data = 0;
    for(int i = 0;i<20;i++)
        LinkAdd(link1,rand()%100);
    LinkPrt(link1);
    PtnLine();
    link1->next = LinkSortGB(link1->next);
    LinkPrt(link1);
    PtnLine();
    //程序运行完成时一定要有输出语句,本工具才能正确展示运行结果。 
	cout << "Hello JSRUN!   \n\n         - from C++ ." << endl;
	return 0;
}
//GuiBing's son code function
Lnodes LinkSGBCollect(Lnodes l1,Lnodes l2){//用来合并
    Lnodes link = new Knodes();
    Lnodes thispoint = link;
    while(l1!=NULL&&l2!=NULL){
        if(l1->data < l2->data){
            thispoint->next = l1;
            l1 = l1->next;
            thispoint = thispoint->next;
        }else{
            thispoint->next = l2;
            l2 = l2->next;
            thispoint = thispoint->next;
        }
    }
    if(l1!=NULL) thispoint->next = l1;
    else thispoint->next = l2;
    thispoint = link->next;
    delete(link);
    return thispoint;
}
//sort 1-100 by 2LuGuiBing
Lnodes LinkSortGB(Lnodes link1){
    if(link1->next == NULL) return link1;
    //如果链表为单节点,直接返回
    Lnodes thispoint = link1;
    Lnodes nextpoint = NULL;
    int number = 0;//number是用来查找一分为二数组的值的
    while(thispoint!= NULL){
        thispoint=thispoint->next;
        number++;//统计当前数组串的长度
    }//这个是
    thispoint = link1;//重新回到头节点位置
    for(int i = 0 ; i < (number-1)/2 ; i++){
        thispoint = thispoint->next;
        //定位到中间的位置
    }
    nextpoint = thispoint->next;
    thispoint->next = NULL;//一分为2
    return LinkSGBCollect(LinkSortGB(link1),LinkSortGB(nextpoint));
}
//revers the link by digui
Lnodes LinkVer_DiGui(Lnodes link1){
    if(link1->next == NULL) return link1;
    Lnodes p = LinkVer_DiGui(link1->next);
    link1->next->next = link1;
    if(link1->next->next == link1) link1->next = NULL; 
    return p;
}
//reverse the link
int LinkVer(Lnodes link1){
    Lnodes HeadPoint = link1,TailPoint = link1;
    while(TailPoint->next!=NULL)    TailPoint = TailPoint->next;
    while(HeadPoint->next!=TailPoint){
        Lnodes Ltong = HeadPoint->next->next;
        HeadPoint->next->next = TailPoint->next;
        TailPoint->next = HeadPoint->next;
        HeadPoint->next = Ltong;
    }

}
//reverse print the link; 
int LinkVerPrt(Lnodes link1){
    if(link1->next != NULL){
        LinkVerPrt(link1->next);
        cout<<link1->next->data<<"-";}
}
//del the Have same value's point
int LinkDelSame(Lnodes link1,int numbers,int D_number){
    Lnodes l = link1->next;
    if(link1->next == NULL) return D_number;
    if(link1->next->data == numbers){
        Lnodes p = link1->next;
        link1->next->data = 1;
        link1->next = link1->next->next;
        delete(p);
        return LinkDelSame(link1,numbers,D_number+1);
    }
    else
        LinkDelSame(link1->next,numbers,D_number);
}
//this is a bounds of n*"-"
void PtnLine(){
    for(int i = 0 ; i < 21 ; i ++) cout<<"-";
    cout<<endl;
}
//Push into the link with data whose type is int
int LinkAdd(Lnodes link1,int data){
    link1->data++;
    Lnodes ThisPoint = link1;
    while(ThisPoint->next != NULL) 
        ThisPoint = ThisPoint->next;
    ThisPoint->next = new Knodes();
    ThisPoint->next->next = NULL;
    ThisPoint->next->data = data;
    return 1;
}
//print the link's value and end last's next are NULL 
int LinkPrt(Lnodes link1){
    cout<<"==>"<<link1->data<<" Numbers\n";
    Lnodes ThisPoint = link1;
    while(ThisPoint->next!=NULL){
        ThisPoint = ThisPoint->next;//Move to next point
        cout<<ThisPoint->data<<"-";
    }
    cout<<endl;
    return 1;
}
//init link and return the head's node
Lnodes LinkInit(){
    cout<<"Successful creation\n";
    Lnodes p = new Knodes();
    p->data = 0;
    p->next = NULL;
    return p;
    // return null;
}