コード例 #1
0
/*
A more difficult problem is to write a function InsertNth() which can insert a
new node at any index within a list. Push() is similar, but can only insert a 
 node at the head end of the list (index 0). The caller may specify any index 
in the range [0..length], and the new node should be inserted so as to be at 
that index.
*/
void insertnthtest()
{
	struct node* head = NULL;
	
	insertnth(&head, 0, 13);	//build 13
	insertnth(&head, 1, 42);	//build 13, 42
	insertnth(&head, 1, 5);		//build 13, 5, 42
	deletelist(&head);
}
コード例 #2
0
ファイル: driver.c プロジェクト: pmiriyals/C_Programs
void testinsertnth()
{
	struct node* node = NULL;
	node = buildlistattailbyref(10);
	printlist(node, "at tail by local ref ");
	insertnth(&node, 10, 100);
	printlist(node, " after inserting at node 10");
}
コード例 #3
0
int main()
{
	int i;
	int *ip;
	struct node *head = NULL;
	struct node *current;

	for(i = 0; i < 10; i++){
		push(&head, i);
	}
	print(head);
	insertnth((&head), 4, 1132);
	printf("\n");
	print(head);
	printf("\n");
}