int main(int argc, char **argv) { //Array statistics double array[5] = {2.0, 3.89, -3.94, 10.1, 0.88}; print_array_stats(array, 5); //Creating liked list with 3 3s and 4 4s linked_list *ll3 = new_linked_list(3, 3); linked_list *ll4 = new_linked_list(4, 4); //Should print: "3 3 3" print_linked_list(ll3, 1, 1); //Inserting a 5 at the 1st position insert_linked_list(ll3, 1, 5); //Should print "3 5 3 3" print_linked_list(ll3, 1, 1); //Printing backwards, should print: "3 3 5 3" print_linked_list(ll3, 1, 0); //Merging the linked lists merge_linked_list(ll3, ll4); //Printing the result, should print: "3 4 5 4 3 4 3 4" print_linked_list(ll3, 1, 1); //Summing the elements, should be 30 printf("Sum: %d\n", sum_linked_list(ll3)); //Freeing the memory of ll3 destroy_linked_list(ll3); }
int main(void) { PNODE phead = NULL;//生成一个头指针,先指向空 int val; int ppos; phead = create_linked_list();//动态生成单链表,并将头节点地址赋给头指针 traverse_linked_list(phead); /*if ( is_empty_linked_list(phead) ) printf("链表空\n"); else printf("链表不空\n"); */ //int len = length_linked_list(phead); //printf("len = %d\n",len); if ( insert_linked_list(phead,3,3,&ppos,&val) ) { printf("在第%d个元素前插入成功,插入的元素是%d\n",ppos,val); } else { printf("在第%d个元素前插入元素%d失败\n",ppos,val); } traverse_linked_list(phead); //sort_linked_list(phead); if ( delete_linked_list(phead,4,&val,&ppos)) { printf("删除成功,删除的元素是第%d个元素%d\n",ppos,val); } else { printf("删除第%d个元素失败\n",ppos); } traverse_linked_list(phead); return 0; }