#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <time.h>
#define _random(x) (random()%x)
using namespace std;
struct LinkNode {
int data;
LinkNode* next;
};
LinkNode* ReverseLink(LinkNode* head)
{
LinkNode *prev=NULL, *next=NULL;
while(head)
{
next = head->next;
head->next = prev;
prev = head;
head = next;
}
return prev;
}
int main()
{
LinkNode* first = NULL;
LinkNode* cur = NULL;
srandom((int)time(0));
for(int i=0; i<10; ++i)
{
LinkNode* pa = new LinkNode;
pa->data = _random(100);
if(cur) {
cur->next = pa;
}
else {
first = pa;
}
cur = pa;
}
cur->next = NULL;
cur = first;
while(cur) {
cout<<cur->data<<" ";
cur = cur->next;
}
cout<<endl;
LinkNode* header = ReverseLink(first);
while(header) {
cout<<header->data<<" ";
header = header->next;
}
cout<<endl;
return 0;
}