c - 数据结构编程算法

标签 c

在计算机科学中,数据结构是在计算机中组织数据以便有效使用数据的一种特殊方式。我的程序在 TurboC++ 上编译时出现错误。它位于 thelearningpoint.net 上。它有 6 个错误。调试一下。请解释一下代码。

#include<stdio.h>
#include<stdlib.h>
typedef struct Node
{int data;
struct Node *next;
struct Node *prev;
}node;

void insert(node *pointer, int data)
{ while(pointer->next!=NULL)
  {pointer=pointer->next;
   }
 pointer->next=(node *)malloc(sizeof(node));
 (pointer->next)->prev=pointer;
 pointer=pointer->next;
 pointer->data=data;
 pointer->next=NULL;
}

void delete(node*pointer,int data)
{ while(pointer->next!=NULL && (pointer->next)->data!=data)
  {pointer=pointer->next;
   }
 if(pointer->next==NULL)
 {printf("Element %d not present",data);
  return;
 }
  node *temp;
  temp=pointer->next;
  pointer->next=temp->next;
  temp->prev=pointer;
  free(temp);
  return;
 }

int main()
{node *start,*temp;
 start=(node *)malloc(sizeof(node));
 temp=start;
 temp->next=NULL;
 temp->prev=NULL;
 printf("1.Insert");
 printf("2.Delete");

 while(1)
{ int query;
  scanf("%d",&query);
  if(query==1)
 {int data;
  scanf("%d",&data);
  insert(start,data);
 }
else if(query==2)
{int data;
scanf("%d",&data);
delete(start,data);
}
} }

最佳答案

因为第38行有一个叫delete的函数,但delete是c++中的关键字,请重命名该函数!

编辑:

正如我的评论者所指出的,您还可以使用正确的编译器

关于c - 数据结构编程算法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33594645/

相关文章:

c++ - native 使用程序集引用

c - 为什么 `\`影响printf的返回值?

c - C 中的 FreeBSD SysCall -> 函数的隐式声明 'modfind'

c++ - 如何在启用显示隐藏文件和文件夹的情况下使用 C\C++ 隐藏

c - 用于对用户输入的数组从最低到最高进行排序的程序。 C语言编程

C 字符串数组

c - 在 For 循环中 fork() 发生了什么

python - 使用 Cython 和 "next"编译

c - 需要帮助在 C 中使用多个返回值

python - 如何在python程序中嵌入C代码?