[C语言程序设计实现输入20个整数数据按从大到小排序计算出]#include<stdio.h> int main() { int a[20],i,j,s; double sum=0,average; for(i=0;i<20;i++){ scanf("%d",&a[i]); sum+=a[i]; } average=sum/20; for(i=1;i<20;i++) for(j=0...+阅读
#include
#include
struct chain
{
int value;
struct chain *next;
};
struct chain *create()
{
struct chain *head,*tail,*p;
int x;
head = tail = NULL;
while(scanf("%d",&x)==1)
{
p=(struct chain*)malloc(sizeof(struct chain));
p->value=x;
p->next=NULL;
if(head==NULL)
head = tail = p;
else
tail=tail->next=p;
}
return head;
}
struct chain *inlink(struct chain *head,int a,int b) //int a代表要插入的节点,int b代表创建节点的数据域
{
struct chain *p,*q,*s;
s = (struct chain *)malloc(sizeof(struct chain));
s->value=b;
if(head==NULL)
{
head = s;
head->next = NULL;
}
if(head->value == a)
{
s->next=head;
head = s;
}
else
{
p=head;
while((p->value!=a)&(p->next!=NULL))
{
q=p;
p=p->next;
}
if(p->value == a)
{
q->next = s;
s->next = p;
}
else
{
p->next=s;
s->next=NULL;
}
}
return (head);
}
struct chain *dellink(struct chain *head,int a) //int a代表要删除的节点
{
struct chain *q,*p;
if(head == NULL)
printf("找不到节点!\n");
else if(head->value == a)
{
p = head;
head = head->next;
}
else
{
p=head;
while((p->value!=a)&(p->next!=NULL))
{
q=p;
p=p->next;
}
if(p->value != a)
printf("链表不存在此节点!\n");
else
{
q->next = p->next;
free(p);
}
}
return (head);
}
void main()
{
struct chain *p,*q;
q=create(); //链表的创建;
//q=inlink(create(),3,1); //链表的插入;
//q=dellink(create(),2); //链表的删除;
while(q){ //输出链表;
printf("%d\n",q->value);
p=q->next;
free(q);
q=p;
}
}
以下为关联文档:
C语言程序设计输入4个数字要求由小到大顺序输出#include<stdio.h> void main() { int a[4],i,j,k; printf("please input four numbers:\n"); for(i=0;i<4;i++) scanf("%d",&a[i]); printf("before Sorting the number is:\n");...
用C语言实现链表的算法这个是我们数据结构上机实验的链表问题, #include<stdio.h> #include<malloc.h> #define LEN sizeof(LinkNode) typedef int Datatype; typedef int Status; typedef struct...
求数据结构线性链表的C语言程序实例这是单链表的创建,取元素,添加,删除和销毁等功能实例: #include#include#define TRUE 1 #define FALSE 0 #define OK 1 #define ERROR 0 typedef int Status; typedef int ElemT...
用C语言实现数据结构中常用算法如对链表的操作查找排序等#include <iostream.h> class ram { public: char wenzi[200]; ram *p; }; ram wo,*ai=&wo; int num=0;//我申请了几次内存了 void xie(void);//输入数据,然后分配内存为下次做...
数据结构c语言描述链表的倒叙输出其实就是栈链,我写了个,你可以参考下 #include#includetypedef struct Node { int data; struct Node *next; }List; void Print(List *top)//打印 { List *p; p=top; while(p...
急数据结构用C语言创建链表#include#includetypedef struct node *pointer; struct node { int data; pointer next; }; pointer next,null,p,L,s,q; int j,e,n,k; creater(int n) { int i; L=(struct...
高手速度来跪求数据结构用C语言编写 1创建链表 L要用到以下函数以前的实验题。 #define OK 1 #define NULL 0 #define ERROR 2 #define ElemType int #include "iostream.h" #include "stdio.h" #include "stdlib.h" typedef struct LNode { in...
数据结构用C语言实现基于链表的学生成绩管理系统根据学号和看可以不咯?#includeintavgGrade(inta[50]){inti,sum=0,max=0,min=0;doubleavg=0.0;max=a[0];min=a[0];for(i=0;imax)max=a[i];if(a[i]a[i]){temp=a[i];a[i]=a[j];a[j]=temp;...
C语言链表操作包括链表的创建删除添加和释放操作!! #include#includestruct node *create(); void print_list(struct node *head); struct node * insert_node(struct node *h,int x,int y...