#include <iostream>using namespace Std;template<typename t>struct node{t data; Node *next; Node (): Next (NULL) {}};template<typename T>class list{public:list () {head = new node<t> ();} void Insert (T x) {node<t> *s = new node<t> (); s->data = X;s->next = Head->next;head->next = s;} void Sort (int x,int y) {node<t> *p = head; Node<t> *q = head; Node<t> *m=p; Node<t> *z=p->next;y++;while (x>=0) {m=p;z=m->next;p=p->next;x--;} while (y>=0) {q=q->next;y--;} node<t> *n = P->next;while (n!=q) {node<t> *k = n->next;n->next=p;p=n;n=k;} m->next=p;z->next=q;//Note Save pointer, clear point. }void Show () {node<t> *p = Head->next;while (p!=null) {cout<<p->data<< "";p =p->next;} Cout<<endl;} Private:node<t> *head;}; int main () {list<int> list;for (int i=0;i<10;i++) {List. Insert (i);} List. Sort (3,6); list. Show (); return 0;}
C + + single-linked list (subscript N to subscript m in reverse order)