[cpp]
#include <stdio.h>
#include <stdlib.h>
struct node
{
int date;
node *next;
}s[100];
int main()
{
int n,i,t;
while(~scanf("%d",&n))
{
node *root,*p;
root = (node *)malloc(sizeof(node));
root -> next = NULL;
p = root;
//建立
for(i = 0 ; i < n ; i ++)
{
node *k = (node *)malloc(sizeof(node));
scanf("%d",&t);
k -> date = t;
k -> next = NULL;
p -> next = k;
p = p -> next;
}
//刪除
int delete_num;
printf("輸入刪除的數據:");
scanf("%d",&delete_num);
p = root;
while(p -> next != NULL)
{
if(p -> next -> date == delete_num)
{
p -> next = p -> next -> next;
break;
}
p = p -> next;
}
//插入
//在有序數列中插入數據
int insert_num;
printf("插入的數據:");
scanf("%d",&insert_num);
p = root;
while(p -> next != NULL)
{
if(p -> next -> date >= insert_num)
{
node *k = (node *)malloc(sizeof(node));
k -> date = insert_num;
k -> next = p -> next;
p -> next = k;
break;
}
p = p -> next;
}
//輸出
p = root;
while(p -> next != NULL)
{
printf("%d ",p -> next ->date);
p = p -> next;
}
}
return 0;
}