[ create a new paste ] login | about

Link: http://codepad.org/UyOunoNW    [ raw code | output | fork ]

C++, pasted on Jan 5:
#include <cstdlib>
#include <iostream>

using namespace std;

 class node 
 {
 	public:
   	int  data;
   	node *link;
 };
 
 void fo(node *p) //輸出 
 {
 	while(p!=NULL)
	{
		cout<<p->data<<endl;
		p=p->link;
	}
 }
 
 node *invert1(node *first)
 {
 	node *p=first;
	node *x0=NULL,*s1;
	
	while(p!=NULL)
	{	
		s1=p->link;
		p->link=x0;
		
		x0=p;
		p=s1;
	}
	first=x0;
	
	return first;
	 
 }
 

int main(int argc, char *argv[])
{ 
	node *a=new node,*b = new node, *c=new node;
	node *first=a;
	
	a->data=10;
	b->data=20; 
	c->data=30;
	a->link=b;
	b->link=c;
	c->link=NULL;
	
	fo(first);
	
	first=invert1(first);
	
	fo(first);
	
		
		

    system("PAUSE");
    return EXIT_SUCCESS;
}


Output:
1
2
3
4
5
6
7
8
10
20
30
30
20
10

Disallowed system call: SYS_fork


Create a new paste based on this one


Comments: