简体   繁体   中英

Data Structures programming algorithm

In computer science, a data structure is a particular way of organizing data in a computer so that it can be used efficiently. My program has got errors when compiled on TurboC++. It is on thelearningpoint.net. It has 6 errors. Debug it. Kindly explain the code.

#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);
}
} }

that's because there is a function called delete on line 38 but delete is a keyword in c++, rename the function!

EDIT:

as pointed out by my commenter you can also use the proper compiler

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM