⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 deldup.c

📁 right threaded binary tree
💻 C
字号:
// delete all duplicate elements//

#include<conio.h>
#include<stdio.h>

typedef struct node1
{
  int info;
  struct node1 *next;
}node;

void crtl(node **start)
{
  *start=NULL;
}

void addate(node **start)
{
  int data;
  node *temp,*temp1;
  temp = (node *) malloc(sizeof(node));
  if(temp==NULL)
  {
   printf("no space\n");
   return;
  }
  printf("element : ");
  scanf("%d",&data);
  temp->info=data;
  temp->next=NULL;
  if(*start==NULL)
    *start=temp;
  else
  {
    temp1=*start;
    while(temp1->next!=NULL)
      temp1=temp1->next;
    temp1->next=temp;
  }
}

void display(node *start)
{
 node *temp;
 temp=start;
 if(temp==NULL)
 {
   printf("empty\n");
   return;
 }
 while(temp!=NULL)
 {
   printf("%d \t",temp->info);
   temp=temp->next;
 }
 printf("\n");
}

void deldup(node **start)
{
  node *temp,*curr,*next,*temp1;
  int data;
  temp=curr=next=temp1=NULL;
  if(*start==NULL)
  {
    printf("empty\n");
    return;
  }
  temp=*start;
  while(temp->next!=NULL)
  {
    curr=temp;
    next=curr->next;
    data=curr->info;
    while(next!=NULL)
      {
	if(data==next->info)
	{
	   temp1=next;
	   curr->next=next->next;
	   free(temp1);
	   next =curr->next;
	}
	else
	{
	  curr=curr->next;
	  next=curr->next;
	}
     }
   temp=temp->next;
  }
  printf("list:\n");
  display(*start);
}

void main()
{
  node *start;
  int n;
  char ch;
  clrscr();
  crtl(&start);
  do
  {
    printf(" 1->insertion\n 2->del duplicate elements\n 3->display\n 4->exit\n");
    scanf("%d",&n);
    switch(n)
    {
      case 1 : do
	       {
		 addate(&start);
		 printf("again : ");
		 fflush(stdin);
		 scanf("%c",&ch);
	       }
	       while(ch=='y' || ch=='Y');
	       break;

      case 2 : deldup(&start);
	       break;

      case 3 : printf("list is: \n");
	       display(start);
	       break;

      case 4 : exit();
	       break;

      default : printf("invalid choice\n");
		break;
    }
  }
  while(n!=4);
 getch();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -