使用这些函数查找链表中的最小元素 int findmin(struct node *) void display(struct node *) void append(struct node **,int) - 用于在末尾添加节点 我尝试过:
find minimum element in linked list using these functions int findmin(struct node *) void display(struct node *) void append(struct node **,int)- for appending node at the end What I have tried:
#include<stdio.h> #include<stdlib.h> struct node { int data; struct node *link; }*start; void append(struct node * , int ); void display(struct node *); int findmin(struct node *); int main() { int value; char ans; if (start==NULL) printf("Enter the value\n"); scanf("%d",&value); append(start,value); ans='Y'; while(ans=='Y') { printf("enter the value\n"); scanf("%d", &value); append(start,value); printf("Do you want to add another node?Type Y/N\n"); scanf("%c",&ans); } printf("the elements in linked list are: "); display(start); printf("The minimum element in the linked list is"); findmin(start); } void append(struct node *start,int value) { struct node *p,*tmp; tmp=(struct node *)malloc(sizeof(struct node)); tmp->data=value; p=start; while(p->link!=NULL) p=p->link; p->link=tmp; tmp->link=NULL; }/*End of addatend()*/ int findmin(struct node *start) { int min=start->data; while(start!=NULL) { if(start->data < min) min = start->data; start=start->link; } return min; }/*End of findmin()*/ void display(struct node *start) { struct node *p; if(start==NULL) { printf("\nList is empty\n"); return; } p=start; while(p!=NULL) { printf("%d",p->data); p=p->link; } printf("\n\n"); }/*End of display() */推荐答案
你的Main需要打印findmin返回的值,目前它调用findmin但是没有对返回值做任何事情。 你有; Your Main needs to print the value returned by findmin, currently it call findmin but does not do anything with the returned value. You have; printf("the elements in linked list are: "); display(start); printf("The minimum element in the linked list is"); findmin(start);
试试;
Try;
printf("the elements in linked list are: "); display(start); printf("The minimum element in the linked list is %d", findmin(start));