[ create a new paste ] login | about

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

C++, pasted on May 23:
#include <iostream>
using namespace std;
 
struct List
{
	int Data;
	List *Next;
};
 
void ShowList(List *current)
{
	while(current!=NULL)
	{	
		cout<<current->Data<<"  ";
		if(current->Next)
			cout<<current->Next->Data<<endl;
		else
			cout<<"NULL"<<endl;
 
		current=current->Next;
	}
}
 
List* NewList(List *head)
{
	if(head==NULL)
	{
		List *NewNode = new List();
 
		NewNode->Data = 100;
		NewNode->Next = NULL;
 
		head = NewNode;
 
		ShowList(head);
		return head;
	}
return NULL;	
}
 
int main() {
	List *OneNode=NULL;
    OneNode = NewList(OneNode);
 
    cout<<"after: "<<endl;
    ShowList(OneNode);
 
    cout<<endl<<"end."<<endl;
	return 0;
}


Output:
1
2
3
4
5
100  NULL
after: 
100  NULL

end.


Create a new paste based on this one


Comments: