示例#1
0
void insert_nth_test()
{
    node_t* head = NULL;
    insert_nth(&head, 0, 13);
    insert_nth(&head, 0, 1);
    insert_nth(&head, 1, 23);
    insert_nth(&head, 1, 4);
//    insert_nth(&head, 17, 40);

    print_list(head);
    //delete_list();
}
示例#2
0
int main(void) {
  cell_t *head_cell = create_cell(0);
  for(int i = 1; i < 11; i++) {
    append_cell(head_cell, create_cell(i));
  }
  printCells(head_cell);
  insert_nth(head_cell, create_cell(100), 3);
  printCells(head_cell);
  return 0;
}
示例#3
0
文件: linkedlist.c 项目: ankitC/rev
void main()
{
	struct node* head = BuildOneTwoThree();
	print_list(head);
//	int count = Count(head, 2);
//	int count = get_nth(head, 0);
//	printf("Count is: %d\n", count);
//	delete_list(&head);
//	print_list(head);
//	int i = 0;
//	int length = list_length(head);
/*	for(i = 0; i<length; i++)
	{
		int c = pop(&head);
		printf("%d\t", c);
	}
	printf("\n");
*/
//	insert_nth(&head,0,10);
//	print_list(head);
#ifdef SORTED_INSERT
	struct node* new_node1 = (struct node*) malloc(sizeof(struct node));
	new_node1->data = 13;
	sorted_insert(&head, new_node1);
	print_list(head);
	struct node* new_node2 = (struct node*) malloc(sizeof(struct node));
	new_node2->data = 0;
	sorted_insert(&head, new_node2);
	print_list(head);
	struct node* new_node3 = (struct node*) malloc(sizeof(struct node));
	new_node3->data = 8;
	sorted_insert(&head, new_node3);
	print_list(head);
	struct node* new_node4 = (struct node*) malloc(sizeof(struct node));
	new_node4->data = 4;
	sorted_insert(&head, new_node4);
	print_list(head);
	struct node* new_node5 = (struct node*) malloc(sizeof(struct node));
	new_node5->data = 30;
	sorted_insert(&head, new_node5);
	print_list(head);
#endif

#ifdef INSERT_SORT
	insert_nth(&head,0,10);
	insert_nth(&head,1,20);
	insert_nth(&head,3,14);
	insert_nth(&head,4,78);
	insert_nth(&head,1,32);
	insert_nth(&head,3,42);
	print_list(head);
	insert_sort(&head);
	print_list(head);
#endif

#ifdef APPEND	
	struct node* head1 = BuildOneTwoThree();
	insert_nth(&head1,0,10);
	print_list(head1);
	append(&head,&head1);
	print_list(head);
	print_list(head1);
#endif

#ifdef SPLIT_FRONT_BACK
	struct node* new_node5 = (struct node*) malloc(sizeof(struct node));
	new_node5->data = 30;
	sorted_insert(&head, new_node5);
	struct node* new_node6 = (struct node*) malloc(sizeof(struct node));
	new_node6->data = 10;
	sorted_insert(&head, new_node6);

	struct node* head1 = NULL;
	struct node* head2=NULL;
	front_back_split(head, &head1, &head2);
	print_list(head1);
	print_list(head2);
#endif
#ifdef REMOVE_DUPLICATES
	struct node* new_node5 = (struct node*) malloc(sizeof(struct node));
	new_node5->data = 2;
	sorted_insert(&head, new_node5);
	struct node* new_node6 = (struct node*) malloc(sizeof(struct node));
	new_node6->data = 1;
	sorted_insert(&head, new_node6);
	print_list(head1);
	remove_duplicates(head1);
	print_list(head1);
#endif

#ifdef MOV_NODE
	struct node* a = BuildOneTwoThree();
	struct node* b = BuildOneTwoThree();
	print_list(a);
	print_list(b);

	move_node(&a,&b);
	print_list(a);
	print_list(b);
#endif

#ifdef ALTERNATING_SPLIT
	struct node* a = NULL;
	struct node* b = NULL;
	alternating_split(head, &a, &b);
	print_list(a);
	print_list(b);
#endif

#ifdef SHUFFLE_MERGE
	struct node* a = BuildOneTwoThree();
	struct node* b = BuildOneTwoThree();
	print_list(a);
	print_list(b);
	struct node* c = shuffle_merge(a,b);
	print_list(c);
#endif

#ifdef SORTED_MERGE
	struct node* a = BuildOneTwoThree();
	struct node* b = BuildOneTwoThree();
	struct node* new_node1 = (struct node*) malloc(sizeof(struct node));
	new_node1->data = 13;
	sorted_insert(&a, new_node1);
	struct node* new_node2 = (struct node*) malloc(sizeof(struct node));
	new_node2->data = 0;
	sorted_insert(&b, new_node2);
	struct node* new_node3 = (struct node*) malloc(sizeof(struct node));
	new_node3->data = 8;
	sorted_insert(&a, new_node3);
	struct node* new_node4 = (struct node*) malloc(sizeof(struct node));
	new_node4->data = 4;
	sorted_insert(&a, new_node4);
	struct node* new_node5 = (struct node*) malloc(sizeof(struct node));
	new_node5->data = 30;
	sorted_insert(&b, new_node5);
	print_list(a);
	print_list(b);
	struct node* c = sorted_merge(a,b);
	print_list(c);
#endif

#ifdef MERGE_SORT
	insert_nth(&head,0,10);
	insert_nth(&head,1,20);
	insert_nth(&head,3,14);
	insert_nth(&head,4,78);
	insert_nth(&head,1,32);
	insert_nth(&head,3,42);
	print_list(head);
	merge_sort(&head);
//	print_list(head);
#endif
	insert_nth(&head,0,10);
	insert_nth(&head,1,20);
	insert_nth(&head,3,14);
	insert_nth(&head,4,78);
	insert_nth(&head,1,32);
	insert_nth(&head,3,42);
	print_list(head);
	reverse(&head);
	print_list(head);

}