# 构造有序的单链表与逆置操作

（可以采用结构化的程序设计方法实现，即不必定义类）

`4 1 6 8 2 0`

```1 2 4 6 8
8 6 4 2 1```

```#include<iostream>
using namespace std;
struct Node
{
int data;
Node *next;
};
{
public:
void Insert(int n);
void reList();
void printList();
private:
Node *p, *s, *first,*r;
};

{
first = new Node;
first->next = NULL;
}

{
Node *front;
s = new Node;
s->data = n;
front = first;
p = first->next;
while (p && n>p->data)
{
front = p;
p = p->next;
}
s->next = p;
front->next = s;
return;
}

{
p = first->next;
first->next = NULL;
while (p)
{
s = p->next;
p->next = first->next;
first->next = p;
p = s;
}
}

{
p = first->next;
while (p)
{
printf("%d ", p->data);
p = p->next;

}
cout << endl;
}

int main()
{
int n = 0;
while (cin>>n && n)
{
myList.Insert(n);
}
myList.printList();
myList.reList();
myList.printList();
}```

```#include <iostream>
#include <set>
using namespace std;
set<int> se;
int main()
{
int n = 0;
while (cin >> n && n) se.insert(n);
for (auto i : se) cout << i << " ";
cout << endl;
set<int>::iterator i = se.end(), j = se.begin();
for (i--, j--; i != j; i--) cout << *i << " ";
}```