链式存储 50 个数,向后插入新节点建立不带头结点的循环单项链表,输出循环链 表及其最大节点值
程序员文章站
2024-03-21 13:32:34
...
#include<stdio.h>
#include<stdlib.h>
#define N 50
typedef struct CirLink{
int data;
CirLink *next;
}CirLink,*Link;
Link p,h=NULL,newP;
//p=h;
void createLink(){
for(int i=0;i<N;i++){
newP=new CirLink;//这里new 与 malloc函数相同
newP->data=i;
newP->next=NULL;
if(h==NULL){
h=newP;
p=h;
}
else{
p->next=newP;
p=p->next;
}
}
newP->next=h;
}
void display(){
Link s=h;
do{
printf("%6d",s->data);
s=s->next;
}while(s->next!=h);
printf("%6d", s->data);
}
void getBiggestNum(){
int max=-1;
Link s1=h;
while(s1->next!=h){
if(s1->data>max){
max=s1->data;
s1=s1->next;
}
s1=s1->next;
}
if(max<s1->data){
max=s1->data;
}
printf("%6d",max);
}
void main(){
system("color 07");
createLink();
display();
getBiggestNum();
}