delete.cpp

来自「Stack, queue, sorting exmaples in C/C++.」· C++ 代码 · 共 69 行

CPP
69
字号
#include<stdio.h>
#include<conio.h>
#include<iostream.h>

struct node{
	int item;
	struct node *next;
	};

typedef struct node NADE;
NADE *start,*cur;

void create()
{
   int i;
   cur=new node;

   printf("enter the num");
   scanf("%d",&i);
   cur->item=i;
   start=cur;
   scanf("%d",&i);

while(i!=-99)
   {
    cur->next=new node;
    cur=cur->next;
    cur->item=i;
    scanf("%d",&i);
    }
cur->next=NULL;
cur=start;
}

void display()
{
 NADE *nod=start;
 while(nod!=NULL)
 {
  printf("[%d] =>",nod->item);
  nod=nod->next;
  }
  printf("NULL");
  }
void add()
{ int i,j;
 NADE *node1, *node2;
  node2=start;
  while(node2!=NULL)
  {
   printf("enter the 1 to delete ");
   scanf("%d",&i);
    if(i==1)
      {
       node2->next=node2->next->next;
	  }
      node2=node2->next;
   } }

  void main()
  {
    create();
    display();
    add();
    display();
    getch();
    }

⌨️ 快捷键说明

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