#include
#include
typedef struct node {
int data;
struct node *next;
}Node, *LinkList;
LinkList head = NULL;
LinkList addNode(int data){
Node* node = (Node*)malloc(sizeof(Node));
node->data = data;
node->next = head;
head = node;
return head;
}
int main()
{
addNode(5);
addNode(8);
addNode(10);
addNode(3);
LinkList ll = head;
int index = 1;
int max = 0, the_index=1;
while(ll){
if(max < ll->data){
max = ll->data;
the_index = index;
}
index++;
ll=ll->next;
}
printf("max data is %d and the index is %d", max, the_index);
return 0;
}
这个就是顺序查找,用一个指针往后走