实验二线的性链表的基本操作实验报告.docxVIP

  • 1
  • 0
  • 约3.08千字
  • 约 10页
  • 2018-02-19 发布于浙江
  • 举报

实验二线的性链表的基本操作实验报告.docx

实验二线的性链表的基本操作实验报告

重庆大学学生上机实验报告上机课程名称:数据结构上机实验名称:实验2实验名称线性链表的基本操作开课学院及实验室:经济与工商管理学院 2011年7月1日学院经管学院年级、专业、班信息管理与信息系统姓名苏浩辉学导教师陈铿成绩教师评语教师签名:【实验目的】建立一线性链表,完成下列功能:1 建立一空表2 建立a1= a ,a2=b,..., a5=e;3 插入 a3 = f;4 删除 a35 每一操作都应该显示出线性表【实验内容】例程程序代码:using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace链式表{classProgram{classlinklist {privateclassNode{publicchar data;publicNode next;public Node() { next = null; }public Node(char data) {this.data = data;this.next = null; } }privateNode head;privateint len;public linklist() { head = newNode(); len = 0; }///////////////////////////////////////////////////////////创建空表完毕publicvoid insert1(char item,int i) {if (i 1) Console.WriteLine(insert location error);if(i==1) {Node q = newNode(item); q.next = head.next; head.next = q;return; }Node p=head ;int j=1;while (p!=nullj1) { p = p.next; ++j; }if (j == 1) {Node q = newNode(); q.next = p.next; p.next = q; } }publicvoid insert2(char item, int i) {if (i 1) Console.WriteLine(insert location error);if (i == 1) { Node q = newNode(item); q.next = head.next; head.next = q; return; } Node p = head; int j = 1; while (p != null j i) { p = p.next; ++j; }if (j == i) {Node q = newNode(item); q.next = p.next; p.next = q; } }publicvoid delete(int i) {int k = 1;Node p = newNode();Node q = newNode(); p = head;while (k i p.next != null) { p = p.next; k = k + 1; }if (p.next.next == null) p.next = null;else { q = p.next;

文档评论(0)

1亿VIP精品文档

相关文档