level 12
一楼度娘
PS.I 将 Information1 Information2 改成所需字串即可使用,如:学号,姓名
PS.II 要增加记录内容,只要改前两个函数就行
PS.III 要更改搜索关键字,只要改第三个函数就行
PS.P 结构化最高~
PS.V 想买
2011年09月23日 13点09分
1
level 12
#include<stdio.h>
//将 Information1 Information2 改成所需字串即可使用,如:学号,姓名
//要增加记录内容,只要改前两个函数就行
//要更改搜索关键字,只要改第三个函数就行
//结构化最高~
char Ver[]="1.0.a";
struct record
{
int info1;
char info2[20];
struct record *next;
}*head=NULL;
void getdata(struct record *temp)
{
printf("Information1(Int):");
scanf("%d",&temp->info1);
printf("Information2(String):");
scanf("%s",temp->info2);
}
void prdata(struct record *temp)
{
printf("Information1:%d\n",temp->info1);
printf("Information2:%s\n",temp->info2);
printf("\n");
}
struct record *search(int keyword)
{
struct record *temp;
int flag=0;
temp=head;
while (temp!=NULL)
{
if (temp->info1==keyword)
{flag=1; break;}
temp=temp->next;
}
if (flag)
return temp;
else
return NULL;
}
void prtitle(char string[17])
{
system("cls");
printf("--------------------------------------------------------------------------------");
printf("| 某 某 管 理 系 统 |");
printf("| ---%s--- |",string);
printf("| |",string);
printf("| 版本号: %s |",Ver);
printf("| --*--版权归属 Noahzark 2010-2020--*-- |");
printf("--------------------------------------------------------------------------------");
printf("\n");
}
void prmenu()
{
prtitle("----------------");
printf(" ---------------------\n");
printf(" |1. 新建数据库 |\n");
printf(" |2. 显示数据库 |\n");
printf(" |3. 查询数据 |\n");
printf(" |4. 插入数据 |\n");
printf(" |5. 删除数据 |\n");
printf(" |9. 销毁数据库 |\n");
printf(" |0. 退出 |\n");
printf(" ---------------------\n");
printf("\n");
printf("请按键:\n");
}
struct record *creat(int n)
{
struct record *start,*temp;
int i;
start=malloc(sizeof(struct record));
temp=start;
getdata(temp);
temp->next=NULL;
for (i=2;i<=n;i++)
{
temp->next=malloc(sizeof(struct record));
temp=temp->next;
getdata(temp);
temp->next=NULL;
}
2011年09月23日 13点09分
2
level 12
return start;
}
void func1()
{
int i,n,flag=1;
prtitle("**-新建数据库-**");
do{
printf("请输入您要建立的初始数据个数(1-9):");
n=getche()-'0';
if (n<10&&n>0)
flag=0;
else
printf("\n输入错误\n");
}while (flag);
printf("\n");
head=creat(n);
printf("数据库创建成功。");
system("Pause");
}
void func2()
{
struct record *temp;
prtitle("**-显示数据库-**");
if (head==NULL)
printf("数据库为空。\n");
else
{
temp=head;
while (temp!=NULL)
{prdata(temp); temp=temp->next;}
}
printf("数据库显示完毕。");
system("Pause");
}
void func3()
{
int keyword;
struct record *temp=NULL;
prtitle("**--查询数据--**");
if (head==NULL)
printf("数据库为空。\n");
else
{
printf("请输入您要查询的Information1:");
scanf("%d",&keyword);
temp=search(keyword);
}
if (temp==NULL)
printf("未查询到目标Information1\n");
else
prdata(temp);
printf("数据查询完成。");
system("Pause");
}
void func4()
{
int keyword;
struct record *temp,*temp2;
prtitle("**--插入数据--**");
if (head==NULL)
printf("数据库为空,请先建立数据库。\n");
else
{
temp=head;
printf("请输入插入目标的前一个Information1:");
scanf("%d",&keyword);
temp=search(keyword);
}
if (temp==NULL)
printf("未查询到目标Information1\n");
else
{
printf("前一位Information1信息:\n");
prdata(temp);
printf("请输入目标信息:\n");
temp2=temp->next;
temp->next=creat(1);
temp->next->next=temp2;
}
printf("数据插入完成。");
system("Pause");
}
void func5()
{
int keyword;
struct record *temp=NULL,*temp2=NULL;
prtitle("**--删除数据--**");
if (head==NULL)
printf("数据库为空。\n");
else
{
printf("请输入您要删除的Information1:");
scanf("%d",&keyword);
temp=search(keyword);
}
if (temp==NULL)
printf("未查询到目标Information1\n");
else
{
printf("您将要删除Information1的信息:\n");
prdata(temp);
if (temp==head)
head=temp->next;
else
{
for (temp2=head;temp2->next!=temp;temp2=temp2->next);
temp2->next=temp->next;
}
free(temp);
}
printf("数据删除完成。");
system("Pause");
}
void func9()
{
struct record *temp;
prtitle("**-销毁数据库-**");
if (head==NULL)
printf("数据库为空。\n");
else
{
temp=head;
while (temp!=NULL)
{free(temp); temp=temp->next;}
head=NULL;
printf("数据库销毁完毕。");
}
system("Pause");
}
int main()
{
system("color F0");
int i=1;
while (i)
{
prmenu();
i=getch()-'0';
switch (i)
{
case 1:func1(); break;
case 2:func2(); break;
case 3:func3(); break;
case 4:func4(); break;
case 5:func5(); break;
case 9:func9(); break;
case 0:printf("程序退出。"); break;
default:printf("按键错误,请重试\n"); system("Pause");
}
}
system("Pause");
return 0;
}
2011年09月23日 13点09分
3
level 12
用了一个小时写的。。。练习链表和结构化= =
OMG我的空格。。。。
附115
htt和p://1谐15.和com/谐file/aqyax3ck#
2011年09月23日 13点09分
5
level 11
顺便这稀烂的把MVC混在一起的设计也该重写了
扔了它吧青年……
2011年09月23日 13点09分
6
level 12
又是
init();
sort();
finish();
么。。。。
2011年09月23日 13点09分
9
level 11
那东西其实不重要,重要的是model, view和controller要分开……
至少先完成抽象的数据结构,然后分层解决M/V/C或者原始数据/内部表示和事件/业务逻辑……什么的
建议看看精区RichOX的XX管理系统教程
2011年09月23日 13点09分
10
level 11
no
it's about layers this time
2011年09月23日 13点09分
11
level 12
啊咧。。。那个更新了么。。。为啥感觉和以前看的不一样呢。。。。
2011年09月23日 13点09分
12
level 11
并非不可,不过我个人对Java语言本身的印象不好就是了
另外去年Excalibur也黄了……我再也不相信Java了——才怪=w=
2011年09月23日 13点09分
16
level 12
哦哦~多谢
某一直打算“C学了解的更多一点之后就学Java”
结果发现学的越多不知道的就越多= =
最近在纠结于process.h 表示咱的操作系统课完全不给力啊。。。连书都没有,一周就一节课,老师上课就照着西安某某出版社的书念。。。
2011年09月23日 13点09分
17
level 11
我自己的OS进程切换还在fatal中,不误人子弟了
不过还是说一句,进程表项什么的,结合进程的各种上下文来看吧
干啃不直观
2011年09月23日 13点09分
18
level 1
举个最简单的例子:
printf("您将要删除Information1的信息:\n");
prdata(temp);
if (temp==head)
head=temp->next;
else
{
for (temp2=head;temp2->next!=temp;temp2=temp2->next);
temp2->next=temp->next;
}
free(temp);
}
printf("数据删除完成。");
system("Pause");
交互与业务逻辑完全混在了一起.
你为什么不拿到用户请求后直接LinkList->erase()? 查找和删除应该算是链表的职责, 而不是交互部分的.
2011年09月23日 14点09分
19