软件技术基础上机实验报告
更新时间:2024-03-22 10:59:01 阅读量: 综合文库 文档下载
电子科技大学
软件技术基础上机实验报告
上机实验二
实验名称:ex2—1
#include \#include \typedef struct node { int data; struct node *next; }node_type;
node_type *create_sllist( ) {
int x; node_type *h, *newnode, *temp;
h= (node_type *) malloc(sizeof(node_type)); h->next = NULL; temp=h; printf(\ scanf(\ while(x!= -1) { newnode=(node_type *)malloc(sizeof(node_type)); if (newnode!=NULL) { newnode->data = x; newnode->next=NULL; temp->next = newnode; temp = newnode; scanf(\ } else { return (h); } } return(h); }
void insert_sllist(node_type *L,int i,int e) { node_type *s,*temp; int j;
temp=L; j=0; while(temp!=NULL&&j
if(temp==NULL||i<1)
printf(\输入位置错误!\ else { s=(node_type*)malloc(sizeof(node_type)); s->data=e;
s->next=temp->next; temp->next=s; } }
node_type *print( node_type *head ) { node_type *temp; temp=head->next; while( temp!=NULL) { printf(\ \ temp=temp->next; } }
void delete_sllist(node_type *list, int i) {
int counter; node_type *temp, *s; temp = list; counter = 0; while(counter
temp=temp->next; }
if (counter!=i-1) {
printf (\
return; } else
{ s = temp->next; temp->next = temp->next->next; free(s); } }
void main() {
int newdata,newp,p; node_type *L; L=create_sllist(); print(L);
printf(\ scanf(\ scanf(\
insert_sllist(L,newp,newdata); print(L);
printf(\ position of the number you want to delete:\\n\ scanf(\ delete_sllist(L,newp); print(L); }
典型数据输入(如图):
应输出(上机前自己分析的结果):1 3 6 8 2 7 上机时遇到的问题:
1、无法同时读取数据和插入位置。 解决办法:分开输入
实际运行结果(如图):
个人体会:
对链表的编写还应加强练习。
实验名称:ex2—2
#include \#include \typedef struct node { int data; struct node *next; }node_type;
node_type *create_sllist( ) {
int x; node_type *h, *newnode, *temp;
h= (node_type *) malloc(sizeof(node_type)); h->next = NULL; temp=h; printf(\ scanf(\ while(x!= 0) { newnode=(node_type *)malloc(sizeof(node_type)); if (newnode!=NULL) { newnode->data = x; newnode->next=NULL; temp->next = newnode; temp = newnode;
scanf(\ } else { return (h); } } return(h); }
void insert_sllist(node_type *L,int e) {
node_type *s,*temp; temp=L; while(temp->next!=NULL) { temp=temp->next; } s=(node_type*)malloc(sizeof(node_type)); s->data=e;
s->next=NULL; temp->next=s; }
node_type *print( node_type *head ) { node_type *temp; temp=head->next; while( temp!=NULL) { printf(\ \ temp=temp->next; } }
void delete_sllist(node_type *list, int i) { node_type *temp, *s; temp = list; while(temp->next->data!=i&& temp->next
{ temp=temp->next;
} s = temp->next; temp->next = temp->next->next; free(s); }
int visit(node_type *L,int n) {
int counter;
NULL) !=
node_type *temp, *s; temp = L; counter = 0; while(temp!= NULL) { if(temp->data!=n) {
counter++;
temp=temp->next;
}
else {
return(1); break; } }
if(temp == NULL) return(0); }
void main() {
int newdata,p; node_type *L; L=create_sllist(); print(L);
printf(\ data \\n\ scanf(\ p=visit(L,newdata); if(p==1) {
printf(\ delete_sllist(L,newdata); print(L); } else {
printf(\ insert_sllist(L,newdata); print(L); } }
典型数据输入(如图):
应输出(上机前自己分析的结果):2 17 63 72 302
2 17 63 5 72 302 7
上机时遇到的问题:
1、删除函数的调用不正确 解决办法:参考书本得以解决
实际运行结果(如图):
实验名称:ex2—3
#include \#include \typedef struct node
{ int data; struct node *next; }node_type;
node_type *create_sllist( ) {
int x; node_type *h, *newnode, *temp;
h= (node_type *) malloc(sizeof(node_type)); h->next = NULL; temp=h; printf(\ scanf(\ while(x!= -1) { newnode=(node_type *)malloc(sizeof(node_type)); if (newnode!=NULL) { newnode->data = x; newnode->next=NULL; temp->next = newnode; temp = newnode; scanf(\ } else { return (h); } } return(h); }
void insert_sllist(node_type *L,int i) {
node_type *s,*temp; temp=L; while(temp!=NULL) { if(i>temp->data&&i
s->next=temp->next; temp->next=s; } else { temp=temp->next; } } }
node_type *print( node_type *head ) { node_type *temp; temp=head->next; while( temp!=NULL) { printf(\ \ temp=temp->next; } }
void main() {
int newdata,newp,p; node_type *L; L=create_sllist(); print(L);
printf(\ scanf(\ insert_sllist(L,newdata); print(L); }
典型数据输入(如图):
应输出(上机前自己分析的结果):5 8 13 22 47 92 103 实际运行结果(如图):
正在阅读:
软件技术基础上机实验报告03-22
四年级上册语文园地七教案【4篇】03-27
毕业设计 - 论文 - 学生宿舍管理系统 - 图文07-03
SQL2000数据库安装教程07-28
关于电子口岸具体操作事项05-20
2014小学三年级数学第七单元测试题12-24
乡镇招商引资上半年工作总结及下半年工作打算(多篇范文)07-08
提高企业职工队伍技术素质浅谈05-12
新课程理念下的初中体育教学研究01-02
国际商务谈判试题(05)及参考答案10-23
- 多层物业服务方案
- (审判实务)习惯法与少数民族地区民间纠纷解决问题(孙 潋)
- 人教版新课标六年级下册语文全册教案
- 词语打卡
- photoshop实习报告
- 钢结构设计原理综合测试2
- 2014年期末练习题
- 高中数学中的逆向思维解题方法探讨
- 名师原创 全国通用2014-2015学年高二寒假作业 政治(一)Word版
- 北航《建筑结构检测鉴定与加固》在线作业三
- XX县卫生监督所工程建设项目可行性研究报告
- 小学四年级观察作文经典评语
- 浅谈110KV变电站电气一次设计-程泉焱(1)
- 安全员考试题库
- 国家电网公司变电运维管理规定(试行)
- 义务教育课程标准稿征求意见提纲
- 教学秘书面试技巧
- 钢结构工程施工组织设计
- 水利工程概论论文
- 09届九年级数学第四次模拟试卷
- 上机
- 软件技术
- 实验
- 基础
- 报告
- 采购材料计划提报管理规定
- 一种基于iBeacon和Wi―Fi的位置空间模型定位方法
- 2010年6月福建高中信息技术会考上机考试选择题(数据管理技术)
- 纪委遴选笔试题及答案
- 高二英语短文改错专题复习
- 2019年苏教版三年级语文上册期末测试题(有答案)(已审阅)
- 城镇建设发展专题报告
- 中班科学课《美丽的菊花》教案 - 图文
- 管理学中的二八法则解读
- 中华人民共和国海关对保税仓库及所存货物管理操作规程
- 扁平化和拟物化设计风格,设计师你该如何选择?
- 《陈涉世家》《高祖本纪》中考阅读练习及答案
- ITE1-6章考试答案
- 巩留镇平安建设典型经验材料
- 宜昌市创建国家卫生城市工作情况汇报
- 浅析桩基础工程
- 计算机网络实验六 检查路由
- 2016大学生心理健康教育考试试卷及答案 - - 超星尔雅
- 2014中考复习《二次函数》精
- 土木工程概论论文