数据结构课程设计 个人通讯录

来源:互联网 发布:魔法王座进阶数据 编辑:程序博客网 时间:2024/04/27 05:04
题目2.李刚是一爱折腾的人,当然爱折腾的人均有梦想,他想当中国的盖次呢。可不,现在个人好友信息多了,复杂了,他想制作一个个人通讯录的制作管理软件。 刚好这个学期学了数据结构课,所以他准备使用数据结构知识来实现了。并考虑使用双向链表作数据结构。并制定了初步要求:

1每个好友信息包含姓名、性别、住址、邮编、几岁、电话、QQ、微信帐号、生日等。

2作为一个完整的系统,应具有友好的界面和较强的容错能力。


                                                                      课程设计报告如下:

 

 

 

 

 

 

《数据结构课程设计》

 

 

 

 

 

 

课程题目

通讯录管理软件--双链表

学生姓名

陈健新

所在专业

信管管理与信息系统

所在班级

信管1133

任课老师

易学明

实习时间

  16-17周

设计成绩

 

老师评语

 

 

 

 

 

 

 

通讯录管理软件--双链表

一、 题目:

李刚是一爱折腾的人,当然爱折腾的人均有梦想,他想当中国的盖次呢。可不,现在个人好友信息多了,复杂了,他想制作一个个人通讯录的制作管理软件。 刚好这个学期学了数据结构课,所以他准备使用数据结构知识来实现了。并考虑使用双向链表作数据结构。并制定了初步要求:

(1)每个好友信息包含姓名、性别、住址、邮编、几岁、电话、QQ、微信帐号、生日等。

(2)作为一个完整的系统,应具有友好的界面和较强的容错能力。

二、 功能需求概述:

    通过调查分析以及结合案例,系统应该达到以下的要求:

(1)系统用户:管理员(即通讯录里任何用户)进行所有的操作,包括查看公告、添加公告、修改公告、删除公告、查看通讯录、添加通讯录、修改通讯录、删除通讯录。

(2)个人通讯录登陆界面:

(3)能够实现个人通讯录基本信息的录入、修改、删除。
 

(4)能够实现通讯录管理系统内公告的录入、修改、删除。

  

(5)系统运行稳定,安全可靠。

(6)用户界面设计美观、友好,使用操作便捷。
三、数据结构分析—双链表(实现数据库(mysql)的逻辑连续):

1.双向链表原理:

在数据结构中,双向链表的存储结构如下图所示:

对指向双向链表任意结点的指针d,有下图的关系:

2.实现方法如下:
根据双向链表的原理,我们在组织数据库中的数据记录(数据项)时,可以将每条记录当作双向链表中的一个节点,不同记录之间的联系不是靠他们ID的大小顺序,而是通过两个指针分别指向上下记录节点。因此,我们必须在每个数据记录中定义三个属性(按照本系统来说):节点号sno,下一条记录节点号next_id,上一条记录节点号prior_id,这样程序调用数据记录进行上下记录切换的时候,不是简单的通过本身ID的加减来实现,而是通过自己的指针项来实现跳转。

添加通讯录逻辑如下:
<?php

    require_once"sqlhelper.php";

    if(isset($_POST['submit'])) {

      $sqlhelper=newsqlhelper();

      $sno=htmlspecialchars($_POST['sno']);

      $name=htmlspecialchars($_POST['name']);

      $sex=$_POST['sex'];

      $address=htmlspecialchars($_POST['address']);

      $telphone=htmlspecialchars($_POST['telphone']);

      $qq=htmlspecialchars($_POST['qq']);

      $birthday=htmlspecialchars($_POST['birthday']);

      $jiguan=htmlspecialchars($_POST['jiguan']);

      $password=md5(htmlspecialchars($_POST['password']));

      //插入所要添加的记录

      $sql="insertinto txl(sno,name,sex,address,telphone,qq,birthday,jiguan,password)values('".$sno."','".$name."','".$sex."','".$address."','".$telphone."','".$qq."','".$birthday."','".$jiguan."','".$password."')";

      $insert_res=$sqlhelper->execute_dql($sql)or die("添加数据失败".mysql_error());

      //定义本记录的指针链接情况

      $prior_id=$sno-'1';//本记录的前驱指针域sno

      $next_id=$sno+'1';//本记录的后继指针域sno

      //更新所要添加记录的指针域

      $sql="updatetxl set prior_id='".$prior_id."',next_id='".$next_id."'where sno='".$sno."'";

      $update_res=$sqlhelper->execute_dql($sql);

      if($update_res) {

          echo"<script>alert('添加通讯录成功');location.href='showtxl.php';</script>";

      }else{

          echo"<script>alert('更新添加记录的指针域失败');location.href='showtxl.php';</script>";

      }

    }

 ?> 

    删除通讯录逻辑如下:
<?php

    header("content-type:text/html;charset=utf-8;");

    require_once'sqlhelper.php';

    $sqlhelper=newsqlhelper();

    @$sno=$_GET['sno'];//获取要删除记录的sno

    $sql="select * fromtxl where sno='$sno'";

    $res=mysql_fetch_assoc($sqlhelper->execute_dql($sql));

    $prior_id=$res['prior_id'];//获取要删除记录sno的前驱指针域prior_id

    $next_id=$res['next_id'];//获取要删除记录sno的后继指针域next_id

    /*****更改上一条记录的右指针使其指向本记录的右指针***/

    $sql="update txl setnext_id='$next_id' where sno='$prior_id'";

    $update_next_id=$sqlhelper->execute_dql($sql);

    /*****更改下一条记录的左指针使其指向本记录的左指针***/

    $sql="update txl setprior_id='$prior_id' where sno='$next_id'";

    $update_prior_id=$sqlhelper->execute_dql($sql);

    /******执行删除操作*******/

    $sql="delete fromtxl where sno='$sno'";

    $delete_res=$sqlhelper->execute_dql($sql);

    if ($delete_res) {

        echo"<script>alert('删除通讯录成功');location.href='showtxl.php';</script>";

    }else{

        echo"<script>alert('删除失败');location.href='showtxl.php';</script>";

    }

 ?>

四、心得体会:
    通过双链表数据结构做个人通讯录管理系统软件,很好地针对当前网络数据库存在的记录操作连续性的问题,我觉得利用双向链表的原理及他的思想,避开了常规的思考方法,可以成功的实现了数据记录的逻辑连续,很好解决了记录操作连续性的问题。而且通过上面的例子,我们可以很清楚看到只要在每次删除记录前,将其连后记录链接起来,由于记录的跳转目的地是记录本身的链接指针决定的,所以保持了数据的连续性,这正是双向链表的优势所在。这样只需要少量的编程代码就节约了系统的大量时间,希望这种有效的实现方法,即双链表数据结构思想,能得到更多的实际应用



功能截图如下


主要代码如下:

<?php require_once "sessionyz.php";       checkusersid(); ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"><title>添加通讯录</title><style type="text/css">#contain table tr{font-size: 20px;text-align: center;height: 40px;}div input{height: 25px;font-size: 15px;vertical-align:text-top;}</style></head><body><?php  include("header.php"); ?><div id="contain" align="center"><form action="addtxl.php" method="post" name="addtxl"><table  width="70%" border="1"><tr ><td  align="left" style="font-size:15px;" height="30" colspan="3" >当前位置---添加通讯录</td></tr><tr><td ><div align="center" class="cen">学号: <input type="text" name="sno" />  姓名: <input type="text" name="name" />    性别:  <input type="radio" name="sex" value="男" checked />男                <input type="radio" name="sex" value="女" />女</div></td></tr><tr><td><div align="center">  宿舍: <input type="text" name="address" />  生日: <input type="text" name="birthday" />  密码: <input type="text" name="password"  /></div></td></tr><tr><td><div  align="center">手机长短号: <input type="text" name="telphone" />  QQ: <input type="text" name="qq" />    籍贯: <input type="text"  name="jiguan" /></div></td></tr><tr><td align="center"><input type="submit" value="提交" name="submit" />    <input type="reset" value="重置" />    <input type="button" name="back" value="返回" onclick="javascript:history.go(-1)" /> </td></tr></table></form></div></body></html><?php require_once "sqlhelper.php";if (isset($_POST['submit'])) {$sqlhelper=new sqlhelper();$sno=htmlspecialchars($_POST['sno']);$name=htmlspecialchars($_POST['name']);$sex=$_POST['sex'];$address=htmlspecialchars($_POST['address']);$telphone=htmlspecialchars($_POST['telphone']);$qq=htmlspecialchars($_POST['qq']);$birthday=htmlspecialchars($_POST['birthday']);$jiguan=htmlspecialchars($_POST['jiguan']);$password=md5(htmlspecialchars($_POST['password']));//插入所要添加的记录$sql="insert into txl(sno,name,sex,address,telphone,qq,birthday,jiguan,password) values('".$sno."','".$name."','".$sex."','".$address."','".$telphone."','".$qq."','".$birthday."','".$jiguan."','".$password."')";$insert_res=$sqlhelper->execute_dql($sql) or die("添加数据失败".mysql_error());//定义本记录的指针链接情况$prior_id=$sno-'1';//本记录的前驱指针域sno$next_id=$sno+'1';//本记录的后继指针域sno//更新所要添加记录的指针域$sql="update txl set prior_id='".$prior_id."',next_id='".$next_id."' where sno='".$sno."'";$update_res=$sqlhelper->execute_dql($sql);if ($update_res) {echo "<script>alert('添加通讯录成功');location.href='showtxl.php';</script>";}else{echo "<script>alert('更新添加记录的指针域失败');location.href='showtxl.php';</script>";}} ?>

</pre><pre name="code" class="php"><?php header("content-type:text/html;charset=utf-8;");require_once 'sqlhelper.php';$sqlhelper=new sqlhelper();@$sno=$_GET['sno'];//获取要删除记录的sno$sql="select * from txl where sno='$sno'";$res=mysql_fetch_assoc($sqlhelper->execute_dql($sql));$prior_id=$res['prior_id'];//获取要删除记录sno的前驱指针域prior_id$next_id=$res['next_id'];//获取要删除记录sno的后继指针域next_id/***** 更改上一条记录的右指针使其指向本记录的右指针***/$sql="update txl set next_id='$next_id' where sno='$prior_id'";$update_next_id=$sqlhelper->execute_dql($sql);/***** 更改下一条记录的左指针使其指向本记录的左指针***/$sql="update txl set prior_id='$prior_id' where sno='$next_id'";$update_prior_id=$sqlhelper->execute_dql($sql);/******执行删除操作*******/$sql="delete from txl where sno='$sno'";$delete_res=$sqlhelper->execute_dql($sql);if ($delete_res) {echo "<script>alert('删除通讯录成功');location.href='showtxl.php';</script>";}else{echo "<script>alert('删除失败');location.href='showtxl.php';</script>";} ?>

<?php require_once "sessionyz.php";       checkusersid(); ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"><title>查看通讯录</title><script type="text/javascript" language="javascript">function show_delete(id){if (confirm("确定要删除该记录?")) {location.href="deletetxl.php?sno="+id;return ture;}else return false; }</script><style type="text/css">#contain table tr,tr th{font-size: 18px;text-align: center;height: 30px; }</style></head><body><?php  include("header.php"); ?><div id="contain" align="center"><table  width="70%" border="1"><tr ><td align="left" style="font-size:15px;" height="30"  colspan="9">当前位置---查看通讯录</td></tr><tr ><th>学号</th><th>姓名</th><th>性别</th><th>手机长短号</th><th>宿舍</th><th>QQ</th><th>生日</th><th>籍贯</th><th>编辑</th></tr><?phprequire_once 'sqlhelper.php';$sqlhelper=new sqlhelper();$sql="select count(sno) from txl";$num=mysql_fetch_row($sqlhelper->execute_dql($sql));if ($num['0']==0) {echo "<tr><td colspan='9' style='font-size:40px;'><b>本站暂无通讯录</b></td></tr>";}else{require_once "txlservice.class.php";//检查是否设置当前页if (isset($_GET['pagenow'])) {$pagenow=intval($_GET['pagenow']);}else{$pagenow=1;}$pagesize=10;//设置页面大小$txlservice= new txlservice();@$table_name="txl";//设置总页数$pagecount=$txlservice->getpagecount($pagesize,$table_name);//显示通讯录信息$res=$txlservice->gettxlbypage($pagenow,$pagesize,$table_name);for ($i=0; $i <count($res) ; $i++) {$row=$res[$i]; echo @"<tr><td>{$row['sno']}</td><td>{$row['name']}</td><td>{$row['sex']}</td><td>{$row['telphone']}</td><td>{$row['address']}</td><td>{$row['qq']}</td><td>{$row['birthday']}</td><td>{$row['jiguan']}</td><td><a href='updatetxl.php?sno=".$row['sno']."'>修改</a><a href='#' onClick='return show_delete(".$row['sno'].");'>删除</a></td></tr>";}?><tr style="font-size:18px;"><td height="30" colspan="9"><div align="right">每页显示<?php echo $pagesize;?>条 第<?php echo $pagenow;?>页/共<?php echo $pagecount ;?>页 <?php $first=1;$prev=$pagenow-1;$next=$pagenow+1;$last=$pagecount;if ($pagenow>1) {echo "<a href='showtxl.php?pagenow=".$first."'>首页</a>";echo " ";echo "<a href='showtxl.php?pagenow=".$prev."'>上一页</a>";echo " ";}if ($pagenow<$pagecount) {echo "<a href='showtxl.php?pagenow=".$next."'>下一页</a>";echo " ";echo "<a href='showtxl.php?pagenow=".$last."'>尾页</a>";} ?></div></td></tr><?php } ?></table></div></body></html>

<?php require_once "sessionyz.php";       checkusersid(); ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"><title>修改通讯录</title><style type="text/css">#contain table tr{font-size: 20px;text-align: center;height: 40px;}div input{height: 24px;font-size: 15px;vertical-align: text-top;}</style></head><body><?php  include("header.php"); require_once 'sqlhelper.php';$sqlhelper=new sqlhelper();@$sno=$_GET['sno'];$sql="select * from txl where sno='$sno'";@$res=mysql_fetch_assoc($sqlhelper->execute_dql($sql));?><div align="center" id="contain"><form action="updatetxl.php" method="post" name="updatetxl"><table  width="70%" border="1" id="contain"><tr><td  align="left" style="font-size:15px;" colspan="3" >当前位置---修改通讯录</td></tr><tr height="40"><td ><div align="center">学号: <input type="text" name="sno" value="<?php echo $res['sno']; ?>" />    姓名: <input type="text" name="name" value="<?php echo $res['name']; ?>" />    性别: <input type="radio" name="sex" value="男" <?php if($res['sex'] != "女") echo "checked";?> />男               <input type="radio" name="sex" value="女" <?php if($res['sex'] == "女") echo "checked";?> />女</div></td></tr><tr><td><div align="center">  宿舍: <input type="text" name="address" value="<?php echo $res['address']; ?>" />  生日: <input type="text" name="birthday" value="<?php echo $res['birthday']; ?>" />  密码: <input type="text" name="password" value="<?php  echo $res['password']; ?>" /></div></td></tr><tr><td><div  align="center">手机长短号: <input type="text" name="telphone" value="<?php echo $res['telphone']; ?>" />    QQ: <input type="text" name="qq" value="<?php echo $res['qq']; ?>" />    籍贯: <input type="text"  name="jiguan" value="<?php echo $res['jiguan']; ?>" /></div></td></tr><tr><td align="center"><input type="hidden" name="sno" value="<?php echo $res['sno'] ?>" /><input type="submit" value="修改" name="submit" />    <input type="reset" value="重置" />  <input type="button" name="back" value="返回" onclick="javascript:history.go(-1)" /> </td></tr></table></form></div></body></html><?php require_once "sqlhelper.php";if (isset($_POST['submit'])) {$sqlhelper=new sqlhelper();$sno=$_POST['sno'];$name=$_POST['name'];$sex=$_POST['sex'];$address=$_POST['address'];$telphone=$_POST['telphone'];$qq=$_POST['qq'];$birthday=$_POST['birthday'];$jiguan=$_POST['jiguan'];//修改记录的指针域链接情况$prior_id=$sno-'1';//前驱$next_id=$sno+'1';//后继//修改记录$sql=" update txl set name='$name',sex='$sex',address='$address',telphone='$telphone',qq='$qq',birthday='$birthday',jiguan='$jiguan',prior_id='$prior_id',next_id='$next_id'  where sno='$sno'";$update_res=$sqlhelper->execute_dql($sql);if ($update_res) {echo "<script>alert('更新通讯录成功');location.href='showtxl.php';</script>";}else{echo "<script>alert('更新通讯录失败');location.href='showtxl.php';</script>";}} ?>




0 0