永发信息网

单链表 在递增有序单链表中插入元素并保持递增有序

答案:6  悬赏:0  手机版
解决时间 2021-03-20 11:33
  • 提问者网友:献世佛
  • 2021-03-20 03:25
单链表 在递增有序单链表中插入元素并保持递增有序
最佳答案
  • 五星知识达人网友:舍身薄凉客
  • 2021-03-20 04:41
typedef struct Node
{
int data;
struct Node *next;
}Node;

void InsertNode(Node *head, Node *s)
{//head 头指针 s插入结点指针
Node *pre = head, *p = head->next;
while(p && p->data < s->data)
{
pre = pre->next;
p = pre->next;
}
s->next = pre->next;
pre->next = s;
}

void DelSameNode(Node *head)
{
Node *pre = head, *p = head->next, q;
while(p->next)
{
if(p->data == p->next->data)
{
pre->next = p->next;
free(p);
p = pre->next;
}
else
{
pre = pre->next;
p = pre->next;
}
}
}
全部回答
  • 1楼网友:动情书生
  • 2021-03-20 08:47
你好一般机油都是5000公里或半年换一次,如果你的车用的是5w/40全合成机油,那就不需要换,因为5w/40是四季通用机油
  • 2楼网友:刀戟声无边
  • 2021-03-20 07:34
1用递归算法对int型数组进行双向选择排序#include
void paixu(int x[],int m,int n)
{
int max,min,e,q,l=m,k=m;
if(m>=n) return;
max=x[m];
for(e=m;e<=n;e++)
{
if(x[e]>max) {l=e;max=x[e];}
}
q=x[n];x[n]=x[l];x[l]=q;
min=x[m];
for(e=m;e<=n;e++)
{
if(x[e]}
q=x[m];x[m]=x[k];x[k]=q;
paixu(x,m+1,n-1);
}
void main()
{
int a[21],b,c,i=1,j,top=0;
printf("请输入数字,中间空格格开,0为结束标志:\n");
scanf("%d",&b);
while(b!=0)
{
a[++top]=b;
scanf("%d",&b);
}
j=top;
paixu(a,i,j);
printf("排序后数组为:\n");
for(c=1;c<=top;c++)
{printf("%d ",a[c]);}
printf("\n");
}
2#include
#include
typedef struct node
{
int data;
struct node *next;
}ln;
ln *set()
{
int x;
ln *head,*s;
head=(ln *)malloc(sizeof(ln));
head->next=NULL;
scanf("%d",&x);
while(x!=0)
{
s=(ln *)malloc(sizeof(ln));
s->data=x;
s->next=head->next;head->next=s;
scanf("%d",&x);
}
return head;
}
void del(ln *b)
{
ln *p,*pre;
int c;
pre=b;p=pre->next;
while(p!=NULL)
{
c=p->data;
ln *p1,*pre1;
pre1=p;p1=p->next;
while(p1!=NULL)
{
if(c==p1->data)
{
p1=p1->next;
pre1->next=p1;
}
else{ pre1=p1;p1=p1->next;}
}
pre=p;
p=p->next;
}
}
void dis(ln *b)
{
ln *p;
p=b->next;
while(p!=NULL)
{
printf("%d ",p->data);
p=p->next;
}
}
void main()
{
ln *a;
a=set();
del(a);
dis(a);
}
  • 3楼网友:爱难随人意
  • 2021-03-20 07:13
typedef struct Node
{
int data;
struct Node *next;
}Node;
void InsertNode(Node *head, Node *s)
{//head 头指针 s插入结点指针
Node *pre = head, *p = head->next;
while(p && p->data < s->data)
{
pre = pre->next;
p = pre->next;
}
s->next = pre->next;
pre->next = s;
}
void DelSameNode(Node *head)
{
Node *pre = head, *p = head->next, q;
while(p->next)
{
if(p->data == p->next->data)
{
pre->next = p->next;
free(p);
p = pre->next;
}
else
{
pre = pre->next;
p = pre->next;
}
}
}
  • 4楼网友:一袍清酒付
  • 2021-03-20 05:36
typedef struct Node
{
int data;
struct Node *next;
}Node;
void InsertNode(Node *head, Node *s)
{//head 头指针 s插入结点指针
Node *pre = head, *p = head->next;
while(p && p->data < s->data)
{
pre = pre->next;
p = pre->next;
}
s->next = pre->next;
pre->next = s;
}
void DelSameNode(Node *head)
{
Node *pre = head, *p = head->next, q;
while(p->next)
{
if(p->data == p->next->data)
{
pre->next = p->next;
free(p);
p = pre->next;
}
else
{
pre = pre->next;
p = pre->next;
}
}
}
  • 5楼网友:街头电车
  • 2021-03-20 04:53
1用递归算法对int型数组进行双向选择排序#include
void paixu(int x[],int m,int n)
{
int max,min,e,q,l=m,k=m;
if(m>=n) return;
max=x[m];
for(e=m;e<=n;e++)
{
if(x[e]>max) {l=e;max=x[e];}
}
q=x[n];x[n]=x[l];x[l]=q;
min=x[m];
for(e=m;e<=n;e++)
{
if(x[e] }
q=x[m];x[m]=x[k];x[k]=q;
paixu(x,m+1,n-1);
}
void main()
{
int a[21],b,c,i=1,j,top=0;
printf("请输入数字,中间空格格开,0为结束标志:\n");
scanf("%d",&b);
while(b!=0)
{
a[++top]=b;
scanf("%d",&b);
}
j=top;
paixu(a,i,j);
printf("排序后数组为:\n");
for(c=1;c<=top;c++)
{printf("%d ",a[c]);}
printf("\n");
}
2#include
#include
typedef struct node
{
int data;
struct node *next;
}ln;
ln *set()
{
int x;
ln *head,*s;
head=(ln *)malloc(sizeof(ln));
head->next=NULL;
scanf("%d",&x);
while(x!=0)
{
s=(ln *)malloc(sizeof(ln));
s->data=x;
s->next=head->next;head->next=s;
scanf("%d",&x);
}
return head;
}
void del(ln *b)
{
ln *p,*pre;
int c;
pre=b;p=pre->next;
while(p!=NULL)
{
c=p->data;
ln *p1,*pre1;
pre1=p;p1=p->next;
while(p1!=NULL)
{
if(c==p1->data)
{
p1=p1->next;
pre1->next=p1;
}
else{ pre1=p1;p1=p1->next;}
}
pre=p;
p=p->next;
}
}
void dis(ln *b)
{
ln *p;
p=b->next;
while(p!=NULL)
{
printf("%d ",p->data);
p=p->next;
}
}
void main()
{
ln *a;
a=set();
del(a);
dis(a);
}
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯