用C语言编程实现单链表的建立,插入,删除,按序号查找和按值查找算法。出现的错误,怎么改

#include <stdio.h>
#include <stdlib.h>
#define TRUE 1
#define FALSE 0
#define LEN sizeof(linklist)

typedef struct node
{
char data;
struct node *next;
}linklist;

//函数声明//
void crtlinked();
void locate_x();
void get_i();
void insert();
void delete_after();
void input_array();
void print_link();
void locate_p();

//全局变量定义//
linklist *head;
char b,x;
linklist *p,*q;
int num;
int i,n;

void main()
{
printf("Creating link_list :\n");
crtlinked();
printf("Print the link list :\n");
print_link();

//查找第五个元素的值//
i=5;
get_i();
printf("Get i=5,the Result is :\n");

//按值查找//
x='b';
printf("Display the result: \n");
printf("Locate x=b,the Result is :\n");
locate_x();

//单链表插入//
printf("\n Insert after p:\n");
locate_p();
b='K';
insert();
print_link();

//单链表删除//
printf("\n Delete after p:\n");
locate_p();
delete_after();
print_link();
}

//建立链表//
void crtlinked()
{
linklist *s;
char ch;
head=NULL;
p=head;
printf("\nPlease input the data(char type) to the list:\n");
printf("If you want to end ,input '#':\n");
scanf("%c",&ch);
while(ch!='#')
{
s=( linklist * )malloc(sizeof(linklist));
s->data=ch;
if (head==NULL)
head=s;
else
p->next=s;
p=s;
scanf("%ch",&ch);
}
p->next=NULL;
}

//按值查找//
void locate_x()
{
if (head==NULL)
printf("The list is empty !\n");
p=head;
while ((p->data!=x)&&(p->next!=NULL))
p=p->next;
if (p->data!=x)
printf("There is no this element\n");
else
printf("There is an element in this list. \n");
}//locate//

//按序号查找//
void get_i()
{
int k;
char val;
if (head==NULL)
printf("This is empty list.\n");
else
{
p=head;
k=1;
while ((k<i)&&(p->next!=NULL))
{
k++;
p->next;
}
if (k==i)
{
val=p->data;
printf("Element=%d",val);
}
else
printf("There is no this element!\n");
}
}//get//

//确定P的指向//
void locate_p()
{
int k=0,k1;
printf("Please in put the position of p:\n");//输入p指向第几个元素//
scanf("%d",&k1);
p=head;
if (head!=NULL)
{
while ((p!=NULL)&&(k<k1))
{
p=p->next;
k++;
}
if (k<k1)
printf("The number is too big or the list is too short !\n");
else
printf("The position of p is %d \n",k1);
}
else
printf("The list is empty !\n");
}//locate_p//

//插入元素//
void insert()
{
linklist *s,*q;
s=(linklist *)malloc(LEN);
s->data=b;
q=head;
while (q->next!=p)
q=q->next;
q->next=s;
s->next=p;
}//insert//

//删除元素//
void delete_after()
{
linklist *r;
r=p->next;
p->next=r->next;
free(r);
}
出现这个
Linking...
1022.obj : error LNK2001: unresolved external symbol "void __cdecl print_link(void)" (?print_link@@YAXXZ)
Debug/1022.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

1022.exe - 2 error(s), 0 warning(s)

错误的意思是没有写print_link()
温馨提示:答案为网友推荐,仅供参考
第1个回答  2012-11-04
print_link去哪里了?
相似回答