《数据结构》课程设计题目2

《数据结构》课程设计题目(2)(这里面夹杂着无数的汗水,希望老师你可以看出来,让我在数据结构里不挂科吧,不胜感激!!)

题目:

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

1每个好友信息包含姓名、性别、住址、邮编、几岁、电话、QQ、微信帐号、生日等。2作为一个完整的系统,应具有友好的界面和较强的容错能力。

分析:

1.首先构建双链表架构。

2.建立C++算法程序。

3.构建界面。

功能:

1.新增联系人。

2.删除联系人。

3.寻找联系人。

4.修改联系人。

5.联系人一览。

6.对于错误的操作进行文字提醒。

图片展示:


</pre>源代码:</p><pre name="code" class="cpp">#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
void init_dlink(void);
void read_file(void);
void write_file(void);
void insert_item(void);
void search_item(void);
void sort_item(void);
void delete_item(void);
void print_item(void);
void modify_item(void);
void anykey(void);
typedef struct node *link;
struct node {
 char man_id[10];
 char name[20];
 char sex[10];
 char address[50];
 char postcode[10];
 char age[10];
 char phone[10];
 char QQ[10];
 char weixin[20];
 char birthday[10];
 link prior,next;
};
link ptr,head,tail,current;
bool fFlag;
int main(void)
{
 char option1,option2;
 system("cls");
 init_dlink();
 read_file();
 while(1)
 {
  system("cls");
  printf("**********************************\n");
  printf(" 1.添加联系人\n");
  printf(" 2.删除联系人\n");
  printf(" 3.寻找联系人\n");
  printf(" 4.联系人一览\n");
  printf(" 5.联系人信息修改\n");
  printf(" 6.退出程序\n");
  printf("**********************************\n");
  printf(" 请输入你的选择(1~5)");
  option1 = getche();
  switch(option1)
  {
   case '1':
    fFlag = 1;
    insert_item();
    break;
   case '2':
    delete_item();
    break;
   case '3':
    search_item();
    break;
   case '4':
    print_item();
    break;
   case '5':
    modify_item();
    break;
   case '6':
    if (fFlag)
    {
     printf("\n");
     printf("保存变化? (Y or N)");
     option2 = getche();
     if(option2 == 'Y')
     {
      write_file();
      exit(0);
     }
     if(option2 = 'N')
      exit(0);
    }
    else
    {
     write_file();
     exit(0);
    }
  }
 }
}
void init_dlink(void)
{
 ptr = (link)malloc(sizeof *ptr);
 strcpy(ptr->man_id,"0");
 strcpy(ptr->name,"0");
 strcpy(ptr->sex,"0");
 strcpy(ptr->address,"0");
 strcpy(ptr->postcode,"0");
 strcpy(ptr->age,"0");
 strcpy(ptr->phone,"0");
 strcpy(ptr->QQ,"0");
 strcpy(ptr->weixin,"0");
 strcpy(ptr->birthday,"0");
 ptr-> prior = ptr;
 ptr->next = ptr;
 head = ptr;
 tail = ptr;
}
void read_file(void)
{
 FILE *fptr;
 if((fptr = fopen("dlist.dat","r")) == NULL)
 {
  printf(" 保存文件不存在!\n");
  printf(" 任意键建立第一个联系人...\n");
  getch();
  insert_item();
 }
 else
 {
  ptr = (link)malloc(sizeof *ptr);
  while(fscanf(fptr,ptr->man_id,ptr->name,ptr->sex,ptr->address,ptr->postcode,ptr->age,ptr->phone,ptr->QQ,ptr->weixin,ptr->birthday) != EOF)
  {
   if(strcmp(ptr->man_id," ") != 0)
   {
    sort_item();
    ptr = (link)malloc(sizeof *ptr);
   }
   else
    free(ptr);
  }
  fclose(fptr);
 }
}
void write_file(void)
{
 FILE *fptr;
 fptr = fopen("dlist.dat","w");
 current = head->next;
 while(current != head)
 {
  fprintf(fptr,"%s %s %s %s %s %s\n",current->man_id,current->name,current->sex,current->address,current->postcode,current->age,current->phone,current->QQ,current->weixin,current->birthday);
  current = current->next;
 }
 fclose(fptr);
}
void insert_item(void)
{
 system("cls");
 ptr = (link)malloc(sizeof *ptr);
 printf(" 序号:");
 gets(ptr->man_id);
 printf(" 姓名:");
 gets(ptr->name);
 printf(" 性别:");
 gets(ptr->sex);
 printf(" 地址:");
 gets(ptr->address);
 printf(" 邮编:");
 gets(ptr->postcode);
 printf(" 年龄:");
 gets(ptr->age);
 printf(" 电话:");
 gets(ptr->phone);
 printf(" QQ:");
 gets(ptr->QQ);
 printf(" 微信:");
 gets(ptr->weixin);
 printf(" 生日:");
 gets(ptr->birthday);
 sort_item();
}
void sort_item(void)
{
 current = head->next;
 while(current != head)
 {
  if(strcmp(ptr->man_id,current->man_id) < 0)
  {
   ptr->next = current;
   ptr->prior = current->prior;
   current->prior->next = ptr;
   current->prior = ptr;
   break;
  }
  current = current->next;
 }
 if(head->next == head || current == head)
 {
  ptr->next = head;
  ptr->prior = head->prior;
  head->prior->next = ptr;
  head->prior = ptr;
  tail = ptr;
 }
}
void delete_item(void)
{
 char del_id[10];
 int count = 0;
 link clear;
 system("cls");
 if(head->next == head)
  printf(" 没有这个人!\n");
 else
 {
  printf(" 序号:");
  gets(del_id);
  current = head->next;
  while(current->next != head)
  {
   if(strcmp(del_id,current->man_id)==0)
   {
    count++;
    clear = current;
    current->prior->next = current->next;
    current->next->prior = current->prior;
    current = current->next;
    free(clear);
   }
   current = current->next;
  }
  if(strcmp(del_id,current->man_id) == 0)
  {
   count++;
   clear = current;
   current->prior->next = head;
   head->prior = current->prior;
   tail = current->prior;
   free(clear);
  }
  if(count > 0)
   printf(" %s 删除这个人\n",del_id);
  else
   printf(" 没有这个人\n",del_id);
 }
 anykey();
}
void search_item(void)
{
 char search_id[10];
 system("cls");
 if(head->next == head)
  printf(" 没有这个人\n");
 else
 {
  printf(" 查找序号:");
  gets(search_id);
  current = head->next;
  while((current != head) && (strcmp(search_id,current->man_id)!=0))
   current = current->next;
  if (current != head)
  {
   printf("--------------------------------------\n");
   printf(" 序号: %s\n",current->man_id);
   printf(" 姓名: %s\n",current->name);
   printf(" 性别: %s\n",current->sex);
   printf(" 地址: %s\n",current->address);
   printf(" 邮编: %s\n",current->postcode);
   printf(" 年龄: %s\n",current->age);
   printf(" 电话: %s\n",current->phone);
   printf(" QQ: %s\n",current->QQ);
   printf(" 微信: %s\n",current->weixin);
   printf(" 生日: %s\n",current->birthday);
   printf("--------------------------------------\n");
  }
  else
   printf(" 没有这个人\n",search_id);
 }
 anykey();
}
void modify_item(void)
{
 int count = 0;
 char modify_id[10];
 system("cls");
 if(head->next == head)
  printf(" 没有这个人的记录\n");
 else
 {
  printf(" 修改联系人的序号:");
  gets(modify_id);
  current = head->next;
  while(current != head)
  {
   if(strcmp(modify_id,current->man_id) == 0)
   {
    printf("******************************\n");
    printf(" 序号: %s\n",current->man_id);
    printf(" 姓名: %s\n",current->name);
    printf(" 性别: %s\n",current->sex);
    printf(" 地址: %s\n",current->address);
    printf(" 邮编: %s\n",current->postcode);
    printf(" 年龄: %s\n",current->age);
    printf(" 电话: %s\n",current->phone);
    printf(" QQ: %s\n",current->QQ);
    printf(" 微信: %s\n",current->weixin);
    printf(" 生日: %s\n",current->birthday);
    printf(" 请输入新地址:");
    gets(current->address);
    printf(" 请输入新邮编:");
    gets(current->postcode);
    printf(" 请输入新年龄:");
    gets(current->age);
    printf(" 请输入新电话:");
    gets(current->phone);
    printf(" 请输入新QQ:");
    gets(current->QQ);
    printf(" 请输入新微信:");
    gets(current->weixin);
    printf(" 请输入新生日:");
    gets(current->birthday);
    count++;
   }
   current = current->next;
  }
  if(count > 0)
   printf(" %d 联系人信息的修改\n",count);
  else
   printf(" 没有这个人\n",modify_id);
 }
 anykey();
}


void print_item(void)
{
 int count = 0;
 system("cls");
 if(head->next == head)
  printf(" 没有联系人信息\n");
 else
 {
  printf(" 序号    姓名    性别    地址    邮编    年龄    电话    QQ    微信    生日\n");
  printf("-------------------------------------------------------------------------------\n");
  current = head->next;
  while(current != head)
  {
   printf(" %-7s  %-12s  %-6s  %-12s  %-12s  %-s\n",current->birthday);
   count++;
   current = current->next;
   if(count % 20 == 0)
    getch();
  }
  printf("-------------------------------------------------------------------------------\n");
  printf(" 信息没有发现\n",count);
 }
 anykey();
}
void anykey(void)
{
 printf(" 任意键继续...");
 getch();
}

收获和体会:

这一次的课程设计我真的花了很多很多的时间和精力去做。因为上学期和这学期编程很不熟悉,我只好通过下载别人的学生管理系统代码来学习,参考并且不断的添加自己的东西。那一份学生管理系统是通过构建类来实现的,但是课程要求确实通过构建双链表来实现。为此我又从网络上找到了一份双链表的构建源代码,并且不断的了解这两份源代码中每一个步骤它所代表的意义,作用。最后再自己重新做一份双链表构建的通讯录。不得不说,这一个过程非常的漫长,并且其中所夹杂的各种错误让我无数次的抓狂。最让我难受的就是在通过我的想法构建双链表的时候,通过不断的查阅书本,想符合自己的想法,又不得不被硬性规定所妥协。我整整做了两天有多的时间才完成了这一次的课程设计。虽然过程非常的艰苦,但是,我也从中收获了非常多有用的东西。例如,我在学构建双链表的时候,也顺便就把单链表的构建学会了。还有许多许多。希望老师你也能看到我的努力,让我在数据结构中也过来吧。不胜感激!

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


【啊哈!算法】算法3:最常用的排序——快速排序       上一节的冒泡排序可以说是我们学习第一个真正的排序算法,并且解决了桶排序浪费空间的问题,但在算法的执行效率上却牺牲了很多,它的时间复杂度达到了O(N2)。假如我们的计算机每秒钟可以运行10亿次,那么对1亿个数进行排序,桶排序则只需要0.1秒,而冒泡排序则需要1千万秒,达到115天之久,是不是很吓人。那有没有既不浪费空间又可以快一点的排序算法
匿名组 这里可能用到几个不同的分组构造。通过括号内围绕的正则表达式就可以组成第一个构造。正如稍后要介绍的一样,既然也可以命名组,大家就有考虑把这个构造作为匿名组。作为一个实例,请看看下列字符串: “08/14/57 46 02/25/59 45 06/05/85 18 03/12/88 16 09/09/90 13“ 这个字符串就是由生日和年龄组成的。如果需要匹配年两而不要生日,就可以把正则
选择排序:从数组的起始位置处开始,把第一个元素与数组中其他元素进行比较。然后,将最小的元素方式在第0个位置上,接着再从第1个位置开始再次进行排序操作。这种操作一直到除最后一个元素外的每一个元素都作为新循环的起始点操作过后才终止。 public void SelectionSort() { int min, temp;
public struct Pqitem { public int priority; public string name; } class CQueue { private ArrayList pqueue; public CQueue() { pqueue
在编写正则表达式的时候,经常会向要向正则表达式添加数量型数据,诸如”精确匹配两次”或者”匹配一次或多次”。利用数量词就可以把这些数据添加到正则表达式里面了。 数量词(+):这个数量词说明正则表达式应该匹配一个或多个紧紧接其前的字符。 string[] words = new string[] { "bad", "boy", "baad", "baaad" ,"bear", "b
来自:http://blog.csdn.net/morewindows/article/details/6678165/归并排序是建立在归并操作上的一种有效的排序算法。该算法是采用分治法(Divide and Conquer)的一个非常典型的应用。首先考虑下如何将将二个有序数列合并。这个非常简单,只要从比较二个数列的第一个数,谁小就先取谁,取了后就在对应数列中删除这个数。然后再进行比较,如果有数列
插入排序算法有两层循环。外层循环会啄个遍历数组元素,而内存循环则会把外层循环所选择的元素与该元素在数组内的下一个元素进行比较。如果外层循环选择的元素小于内存循环选择的元素,那么瘦元素都想右移动以便为内存循环元素留出位置。 public void InsertionSort() { int inner, temp;
public int binSearch(int value) { int upperBround, lowerBound, mid; upperBround = arr.Length - 1; lowerBound = 0; while (lowerBound <= upper
虽然从表内第一个节点到最后一个节点的遍历操作是非常简单的,但是反向遍历链表却不是一件容易的事情。如果为Node类添加一个字段来存储指向前一个节点的连接,那么久会使得这个反向操作过程变得容易许多。当向链表插入节点的时候,为了吧数据复制给新的字段会需要执行更多的操作,但是当腰吧节点从表移除的时候就能看到他的改进效果了。 首先需要修改Node类来为累增加一个额外的链接。为了区别两个连接,这个把指
八、树(Tree)树,顾名思义,长得像一棵树,不过通常我们画成一棵倒过来的树,根在上,叶在下。不说那么多了,图一看就懂:当然了,引入了树之后,就不得不引入树的一些概念,这些概念我照样尽量用图,谁会记那么多文字?树这种结构还可以表示成下面这种方式,可见树用来描述包含关系是很不错的,但这种包含关系不得出现交叉重叠区域,否则就不能用树描述了,看图:面试的时候我们经常被考到的是一种叫“二叉树”的结构,二叉
Queue的实现: 就像Stack类的实现所做的一样,Queue类的实现用ArrayList简直是毋庸置疑的。对于这些数据结构类型而言,由于他们都是动态内置的结构,所以ArrayList是极好的实现选择。当需要往队列中插入数据项时,ArrayList会在表中把每一个保留的数据项向前移动一个元素。 class CQueue { private ArrayLis
来自:http://yingyingol.iteye.com/blog/13348911 快速排序介绍:快速排序是由东尼·霍尔所发展的一种排序算法。在平均状况下,排序 n 个项目要Ο(n log n)次比较。在最坏状况下则需要Ο(n2)次比较,但这种状况并不常见。事实上,快速排序通常明显比其他Ο(n log n) 算法更快,因为它的内部循环(inner loop)可以在大部分的架构上很有效率地
Stack的实现必须采用一种基本结构来保存数据。因为再新数据项进栈的时候不需要担心调整表的大小,所以选择用arrayList.using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Collecti
数组类测试环境与排序算法using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace Data_structure_and_algorithm{ class CArray { pr
一、构造二叉树 二叉树查找树由节点组成,所以需要有个Node类,这个类类似于链表实现中用到的Node类。首先一起来看看Node类的代码。 public class Node { public int Data; public Node Left; public Node Right; public v
二叉树是一种特殊的树。二叉树的特点是每个结点最多有两个儿子,左边的叫做左儿子,右边的叫做右儿子,或者说每个结点最多有两棵子树。更加严格的递归定义是:二叉树要么为空,要么由根结点、左子树和右子树组成,而左子树和右子树分别是一棵二叉树。 下面这棵树就是一棵二叉树。         二叉树的使用范围最广,一棵多叉树也可以转化为二叉树,因此我们将着重讲解二叉树。二叉树中还有连两种特殊的二叉树叫做满二叉树和
上一节中我们学习了队列,它是一种先进先出的数据结构。还有一种是后进先出的数据结构它叫做栈。栈限定只能在一端进行插入和删除操作。比如说有一个小桶,小桶的直径只能放一个小球,我们现在向小桶内依次放入2号、1号、3号小球。假如你现在需要拿出2号小球,那就必须先将3号小球拿出,再拿出1号小球,最后才能将2号小球拿出来。在刚才取小球的过程中,我们最先放进去的小球最后才能拿出来,而最后放进去的小球却可以最先拿
msdn中的描述如下:(?= 子表达式)(零宽度正预测先行断言。) 仅当子表达式在此位置的右侧匹配时才继续匹配。例如,w+(?=d) 与后跟数字的单词匹配,而不与该数字匹配。此构造不会回溯。(?(零宽度正回顾后发断言。) 仅当子表达式在此位置的左侧匹配时才继续匹配。例如,(?此构造不会回溯。msdn描述的比较清楚,如:w+(?=ing) 可以匹配以ing结尾的单词(匹配结果不包括ing),(
1.引入线索二叉树 二叉树的遍历实质上是对一个非线性结构实现线性化的过程,使每一个节点(除第一个和最后一个外)在这些线性序列中有且仅有一个直接前驱和直接后继。但在二叉链表存储结构中,只能找到一个节点的左、右孩子信息,而不能直接得到节点在任一遍历序列中的前驱和后继信息。这些信息只有在遍历的动态过程中才能得到,因此,引入线索二叉树来保存这些从动态过程中得到的信息。 2.建立线索二叉树 为了保
排序与我们日常生活中息息相关,比如,我们要从电话簿中找到某个联系人首先会按照姓氏排序、买火车票会按照出发时间或者时长排序、买东西会按照销量或者好评度排序、查找文件会按照修改时间排序等等。在计算机程序设计中,排序和查找也是最基本的算法,很多其他的算法都是以排序算法为基础,在一般的数据处理或分析中,通常第一步就是进行排序,比如说二分查找,首先要对数据进行排序。在Donald Knuth 的计算机程序设