实验11_4_初识链表
#include <stdio.h>
#include <stdlib.h>
struct Node
{
int data;
struct Node *next;
};
int main()
{
struct Node* head=(struct Node*)malloc(sizeof(struct Node*));
head->next=NULL;
struct Node* current=(struct Node*)malloc(sizeof(struct Node*));
current=head;
int i;
while(1)
{
scanf("%d",&i);
if(i==-1)
break;
struct Node* temp=(struct Node*)malloc(sizeof(struct Node*));
temp->data=i;
temp->next=NULL;
current->next=temp;
current=temp;
}
current=head->next;
int sum=0,MAX=0,MIN=current->data;
while(1)
{
sum+=current->data;
if(current->data<MIN)
MIN=current->data;
if(current->data>MAX)
MAX=current->data;
if(current->next==NULL)
break;
current=current->next;
}
printf("The maximum,minmum and the total are:%d %d %d",MAX,MIN,sum);
}