不知道要做成什么样子的
#include <stdio.h>
#include <stdlib.h>
#define LEN
sizeof( struct LNode )
typedef struct LNode
{
int food;//食品费用
int house;//房租费用
int education;//教育费用
int charge;//水电费用
int healthy;//医疗费用
int in;//收入
int sum;//总的消费
int month;//月份
struct LNode *next;
}*SqList;
//1创建空链表
void Creat_List( SqList &L )
{
L = (SqList) malloc (LEN);
if( !L )
exit(0);
L->next = NULL;
printf("信息初始化成功!\n");
}
//2插入链表元素
void Insert_List( SqList &L )
{
SqList q;
q = (SqList) malloc (LEN);
if( !q )
exit(0);
printf("输入你要记入的月份:");
scanf("%d", &q->month);
printf("输入本月食品费用:");
scanf("%d",&q->food );
printf("输入本月房租费用:");
scanf("%d",&q->house);
printf("输入本月教育费用:");
scanf("%d",&q->education);
printf("输入本月水电费用:");
scanf("%d",&q->charge );
printf("输入本月医疗费用:");
scanf("%d",&q->healthy );
printf("输入本月收入:");
scanf("%d",&q->in);
q->sum = q->food + q->house + q->education +
q->charge + q->healthy;
q->next = L->next;
L->next = q;
}
//3删除链表结点
void Delete_List( SqList &L )
{
SqList p = L;
int mon;
printf("输入要删除信息的月份:");
scanf("%d", &mon );
while( p->next )
{
if( p->next->month == mon )
{
p->next = p->next->next;
printf("删除成功!\n");
break;
}
p = p->next;
}
}
//4输出全部信息
void Output_List( SqList L )
{
SqList p = L->next;
while( p )
{
printf("%d 月份:\n", p->month );
printf("本月食品费用: %d\n", p->food );
printf("本月房租费用: %d\n", p->house );
printf("本月教育费用: %d\n", p->education );
printf("本月水电费用: %d\n", p->charge );
printf("本月医疗费用: %d\n", p->healthy );
printf("本月收入: %d\n", p->in );
printf("本月总费用: %d\n", p->sum );
p = p->next;
}
}
//5链表排序依消费从少到多
void Arrang_List( SqList L )
{
if( !L->next )
return;
SqList p, rear, front, temp;
front = L;
p = L->next;
rear = p->next;
while( rear )
{
if( p->sum > rear->sum )
{
front->next = p->next;
temp = p->next;
p->next = rear->next;
rear->next = temp;
temp = rear;
rear = p;
p = temp;
}
front = front->next;
p = p->next;
rear = rear->next;
}
Output_List( L );
}
//6查询链表某一结点的信息 并返回值
void Check_List( SqList L, SqList &e )
{
SqList q = L->next;
int mon;
printf("输入要查询或修改信息的月份:");
scanf("%d", &mon );
while(q)
{
if( q->month == mon )
{
e = q;
break;
}
q = q->next;
}
if( !q )
{
printf("表中不存在当前要查找或修改的信息!\n");
e = NULL;
}
}
//7修改链表结点的信息
void Change_List( SqList &L )
{
SqList e = (SqList) malloc (LEN);
Check_List( L, e );
if( !e )
return;//想要修改的结点不存在
printf("修改本月食品费用:");
scanf("%d",&e->food );
printf("修改本月房租费用为:");
scanf("%d",&e->house );
printf("修改本月教育费用为:");
scanf("%d",&e->education );
printf("修改本月水电费用为:");
scanf("%d",&e->charge );
printf("修改本月医疗费用为:");
scanf("%d",&e->healthy );
printf("修改本月收入为:");
scanf("%d",&e->in );
e->sum = e->food + e->house + e->education +
e->charge + e->healthy;
printf("信息修改成功!\n");
}
int main()
{
SqList L, e;
int c;
Creat_List( L );
while( 1 )
{
printf("#输入\'1\'增加月份信息#\n");
printf("#输入\'2\'删除月份信息#\n");
printf("#输入\'3\'输出所有月份信息#\n");
printf("#输入\'4\'按消费从少到多输出月份信息#\n");
printf("#输入\'5\'查询月份信息#\n");
printf("#输入\'6\'修改月份信息#\n");
printf("#输入\'7\'退出系统#\n");
scanf("%d", &c);
getchar();
switch( c )
{
case 1:
Insert_List( L );
break;
case 2:
Delete_List( L );
break;
case 3:
Output_List( L );
break;
case 4:
Arrang_List( L );
break;
case 5:
Check_List( L, e );
//printf("%d 月份:\n", q->month );
if( e )
{
printf("本月食品费用: %d\n", e->food );
printf("本月房租费用: %d\n", e->house );
printf("本月教育费用: %d\n", e->education );
printf("本月水电费用: %d\n", e->charge );
printf("本月医疗费用: %d\n", e->healthy );
printf("本月收入: %d\n", e->in );
printf("本月总费用: %d\n", e->sum );
}
break;
case 6:
Change_List( L );
break;
case 7:
exit(0);
break;
}
}
return 0;
}