本文介绍了我的c程序中的链接器错误。该程序在双向链表中插入和删除。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 以下代码是在不同位置的双向链表中插入和删除的程序。它正在编译,但没有运行,因为它显示3个链接器错误。请尽快帮助。谢谢。问候。 The following code is a program for insertion and deletion in a doubly linked list at various positions. It is getting compiled, but not running as it shows 3 linker errors. Please help ASAP. Thankyou. Regards. #include<alloc.h>#include<conio.h>#include<stdio.h>#include<stdlib.h>struct node {struct node *prev;int n;struct node *next;} *h, *temp, *temp1, *temp2, *temp4;void create();void insert_beg();void insert_end();void delete_pos();void traverse();int count = 0;void main(){int ch;clrscr();printf("\n1.Create list\n2.Insert at beginning\n3.Insert at end\n4.Delete from given position\n5.Display");while (1){printf("\n Enter your choice: ");scanf("%d", &ch);switch (ch){case 1:create_list();break;case 2:insert_beg();break;case 3:insert_end();break;case 4:delete_pos();break;case 5:traverse();break;default:printf("\n Wong choice entered");}getch();}}void create(){int data;temp = (struct node *)malloc(1 * sizeof(struct node));temp->prev = NULL;temp->next = NULL;printf("\n Enter the data: ");scanf("%d", &data);temp->n = data;count++;}void insert_beg(){if (h == NULL){create();h = temp;temp1 = h;}else{create();temp->next = h;h->prev = temp;h = temp;}}void insert_end(){if (h == NULL){create();temp->next = temp;temp->prev = temp1;temp1 = temp;}}void del_pos(){int i = 1, pos;printf("\n Enterposition to be deleted: ");scanf("%d", &pos);temp2 = h;if ((pos & lt; 1) || (pos & gt; = count + 1)){printf("\n Error: Position out of range to delete");return;}if (h == NULL){printf("\n Error: Empty iist");return;}else{while (i & lt; pos){temp2 = temp2->next;i++;}if (i == 1){if (temp2->next == NULL){printf("Node deleted from list");free(temp2);temp2 = h = NULL;return;}}if (temp->next == NULL){temp2->prev->next = NULL;free(temp2);printf("Node deleted from list");return;}temp2->next->prev = temp2->prev;if (i != 1)temp2->prev->next = temp2->next;if (i == 1)h = temp2->next;printf("\n Node deleted");free(temp);}count--;}void diaplay(){temp2 = h;if (temp2 == NULL){printf("List empty to traverse\n");return;}printf("\n Lined list is:\n ");while (temp2->next != NULL){printf("%d", temp2->n);temp2 = temp2->next;}printf("%d", temp2->n);getch();} 推荐答案 [...] undefined reference to `create_list'[...] undefined reference to `delete_pos'[...] undefined reference to `traverse' 因为你正在调用这些函数但它们没有被定义(它们没有正文)。Because you are calling such functions but they aren't defined (they have no body). Quote: 解决方案(错误已解决): solution(errors rectified):#include<malloc.h>#include<conio.h>#include<stdio.h>#include<stdlib.h>struct node { struct node *prev; int n; struct node *next;} *h, *temp, *temp1, *temp2, *temp4;void create_list();void insert_beg();void insert_end();void delete_pos();void traverse();int count = 0;void main(){ int ch; system("cls"); printf("\n1.Create list\n2.Insert at beginning\n3.Insert at end\n4.Delete from given position\n5.Display"); while (1) { printf("\n Enter your choice: "); scanf("%d", &ch); switch (ch) { case 1: create_list(); break; case 2: insert_beg(); break; case 3: insert_end(); break; case 4: delete_pos(); break; case 5: traverse(); break; default: printf("\n Wong choice entered"); } getch(); }}void create_list(){ int data; temp = (struct node *)malloc(1 * sizeof(struct node)); temp->prev = NULL; temp->next = NULL; printf("\n Enter the data: "); scanf("%d", &data); temp->n = data; count++;}void insert_beg(){ if (h == NULL) { create_list(); h = temp; temp1 = h; } else { create_list(); temp->next = h; h->prev = temp; h = temp; }}void insert_end(){ if (h == NULL) { create_list(); temp->next = temp; temp->prev = temp1; temp1 = temp; }}void delete_pos(){ int i = 1, pos, gt,lt; printf("\n Enterposition to be deleted: "); scanf("%d", &pos); temp2 = h; if (h == NULL) { printf("\n Error: Empty iist"); return; } else { while (i & lt, pos) { temp2 = temp2->next; i++; } if (i == 1) { if (temp2->next == NULL) { printf("Node deleted from list"); free(temp2); temp2 = h = NULL; return; } } if (temp->next == NULL) { temp2->prev->next = NULL; free(temp2); printf("Node deleted from list"); return; } temp2->next->prev = temp2->prev; if (i != 1) temp2->prev->next = temp2->next; if (i == 1) h = temp2->next; printf("\n Node deleted"); free(temp); } count--;}void traverse(){ temp2 = h; if (temp2 == NULL) { printf("List empty to traverse\n"); return; } printf("\n Lined list is:\n "); while (temp2->next != NULL) { printf("%d", temp2->n); temp2 = temp2->next; } printf("%d", temp2->n); getch();} 注意: 你在函数del_pos的if部分使用了未声明的变量。因为它只是一个错误消息我已经删除了它。如果你想要它,请声明变量gt&使用它。删除的部分在下面给出了您的身份证明。 Note:you have used undeclared variables in the if part of the function del_pos.Since it is just an error message I have deleted it.If you want it kindly declare the variables gt & lt and use it.The deleted part is given below for your identification.if ((pos & lt; 1) || (pos & gt; = count + 1)) { printf("\n Error: Position out of range to delete"); return; } 这篇关于我的c程序中的链接器错误。该程序在双向链表中插入和删除。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-27 17:46