帮忙看看这个用C定义的链表的删除操作的错误

来源:百度知道 编辑:UC知道 时间:2024/06/18 01:55:55
void del()
{
struct node ;

int a;

printf("\n The delete no.: ");
scanf("%d",&a);
if(
(node,NODE_NUM-1,a)!= -1 )
{printf("founs and delet");
}
else
{ printf("\nNot found !");
getch();
}
}

你这个程序里没有任何针对链表的操作。
你可以查阅一下C语言相关书籍。
在此引用一段程序你可以参考一下:
struct node *delet(head,pstr)以/* head为头指针,删除pstr所在节点 */
struct node *head;
char *pstr;
{
struct node *temp,*p;
temp = head; /* 链表的头指针 */
if (head == NULL) /* 链表为空 */
printf("\nList is null!\n");
else /* 非空表 */
{
temp = head ;
while( strcmp(temp->str,pstr) != 0 && temp->next != NULL )
/* 若节点的字符串与输入字符串不同,并且未到链表尾 */
{
p = temp;
temp = temp -> next; / *跟踪链表的增长,即指针后移 */
}
if(strcmp(temp->str,pstr)==0 ) /* 找到字符串 */
{
if(temp==head)/* 表头节点 */
{
printf("delete string :%s\n",temp->str);
head = head -> next;
free(temp); / *释放被删节点* /
}
else
{
p -> next = temp -> next; /* 表中节点 */
printf("delete string :%s\n"