[ create a new paste ] login | about

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

C, pasted on Nov 20:
#include <stdio.h>
#include <stdlib.h>

typedef struct _Node {
	struct _Node *next;
	int key;
} Node, *pNode;



// ======================================
// declare
pNode create(int key);
void push_back(pNode head, int key);
void travel(pNode head);
pNode push_font(pNode head,int key);

// ======================================
// Create
pNode create(int key)
{
	pNode head = (pNode)malloc(sizeof(Node));
	head->key = key;
	head->next = NULL;
	return head;
}
// ======================================
// push_back
void push_back(pNode head, int key)
{
	pNode New = create(key);
	pNode tmp = head;
	while(head->next!=NULL) head = head->next;
	head->next = New;
	New->next = NULL;
}
// ======================================
// travel
void travel(pNode head)
{
	pNode tmp;
	if(head==NULL) {
		printf("(NULL)");
		return;
	}
	tmp = head;
	while(tmp!=NULL){
		printf("%d ", tmp->key);
		tmp = tmp->next;
	}
}
// ======================================
// push_font
pNode push_font(pNode head, int key)
{
	pNode New = (pNode)malloc(sizeof(Node));
	New->key = key;
	New->next = head;
	return New;
}
// ======================================
int main()
{
	int i;
	pNode head = create(0);
	for(i=4; i<=6; i++) head = push_font(head, i);
	travel(head);
	getchar();
	return 0;
}


Output:
1
6 5 4 0 


Create a new paste based on this one


Comments: