#include
#include
#include
typedef struct node //定义节点
{
int value;
struct node* next;
}note;
note* head = NULL;
void del (note** head, int k)//删除链表
{
note* pp;
note* pt;
note* pq;
pp = *head;
if ((*head)->value == k)//如果头结点的值等于k,删除头结点
{
*head = (*head)->next;
return;
}
while(pp->value != k)
{
pt = pp;
pq = pp->next;
pp = pq;
}
pt->next = pp->next;//删除结点
}
void insert(note** head, int q)//建立链表
{
note* pp;
note* pt;
note* p = (note*)malloc(sizeof(note));
p->value = q;
p->next = NULL;
pp = *head;
if (*head==NULL)
{
*head=p;
return;
}
while(pp->next!=NULL)
{
pt = pp->next;
pp = pt;
}
pp->next = p;
}
void print(note* head)//打印链表
{
note* pp;
while(head!=NULL)
{
printf("%d ", head->value);
pp = head->next;
head = pp;
}
}
int main()
{
int i;
int n,k,value;
scanf("%d %d",&n, &k);
for(i=0; i
scanf("%d", &value);
insert(&head, value); //把head的地址传过去
}
del(&head, k);
print(head);
getch();//随意按个键退出界面
return 0;
}
int main(int argc, char** argv)
{
int dest[1024]; // 存储输入的数据
int result[1024]; // 存储最后的结果 这里只是简单的用数组,你完全可以自己写个list
int ntotal = getc(); // getc函数不知道写的对不对,没有查看api
int ndel = getc();
/*获取用户输入的数据*/
int i = -1;
while (++i < ntotal)
dest[i] = getc();
/*判断是否等于ndel,如果不相等则放在result数组中*/
i = -1;
int j = -1;
while (i < ntotal)
if (dest[i] != ndel)
result[++j] = dest[i];
/*打印result数组,你自己打印吧*/
return 0;
}