题解 | #牛牛的链表删除#
牛牛的链表删除
https://www.nowcoder.com/practice/d3df844baa8a4c139e103ca1b1faae0f
#include <stdio.h>
typedef struct Node{
int data;
struct Node* next;
} node;
node* cai(int v){
node* kk=(node*)malloc(sizeof(node));
kk->data=v;
kk->next=NULL;
return kk;
}
int main(){
int n;
int k;
scanf("%d",&n);
scanf("%d",&k);
node* head=NULL;
node* tail=NULL;
for(int i=0;i<n;i++){
int v;
scanf("%d",&v);
if(v==k){
continue;
}
node* f=cai(v);
if(head==NULL){
head=f;
tail=f;
}else{
tail->next=f;
tail=f;
}
}
node* p=head;
while(p!=NULL){
printf("%d ",p->data);
p=p->next;
}
}
查看12道真题和解析