#include<stdio.h> #include<malloc.h> #include<windows.h> #include"typet.h" node *Creat(){ node *h,*s,*r; h=malloc(sizeof(node)); h->next=NULL; r-h; s=malloc(sizeof(node)); printf("名称:\n"); scanf("%s",&s->data.name); printf("增加时间:\n"); scanf("%s",&s->data.time); printf("手机尾号:\n"); scanf("%s",&s->data.useful); printf("类型:\n"); scanf("%s",&s->data.type); r->next=s; r=s; r->next=NULL; return h; } void print(node *s){ while (s->next!=NULL){ s=s->next; printf("名称:"); printf("%s",&s->data.name); printf("增加时间:"); printf("%s",&s->data.time); printf("手机尾号:"); printf("%s",&s->data.useful); printf("类型:"); printf("%s",&s->data.type); } } void save(node *s){ int id=MessageBox(NULL,"是否保存文件!","保存文件",MB_YESNO); if(id==IDYES) { FILE *fp;//创建文件指针 int n; fp=fopen("f1,txt","a"); while (s->next!=NULL){ s=s->next; fprintf(fp,"%s\n",s->data.name); fprintf(fp,"%lf\n",s->data.time); fprintf(fp,"%s\n",s->data.useful); fprintf(fp,"%d\n",s->data.type); } fclose(fp); MessageBox(NULL,"保存文件成功!","保存文件",MB_OK); main(); } else main(); } void outFile(){ pubname t; FILE *fp; if((fp=fopen("f1.txt","r"))==NULL){//w 新建,a 追加 MessageBox(NULL,"文件打开失败!","读取文件",MB_OK); main(); } while (!feof(fp)){ fscanf(fp,"%s",t.name); fscanf(fp,"%s",t.time); fscanf(fp,"%s",t.useful); fscanf(fp,"%s",t.type); printf("名称:"); printf("%s\n",t.name); printf("增加时间:"); printf("%s\n",t.time); printf("用途:"); printf("%s\n",t.useful); printf("类型:"); printf("%s\n",t.type); } fclose(fp); }将这段代码添加其中是否会解决

时间: 2024-04-07 18:28:04 浏览: 13
将这段代码添加进去可以解决查询功能的问题。在ViesPub()函数中,可以调用print()函数来打印所有订单的信息,而print()函数中调用的order()函数可以获取所有订单的信息。同时,可以添加一个save()函数来保存所有订单的信息到文件中,以便下次查询。此外,outFile()函数也可以用来从文件中读取订单信息并打印出来。
相关问题

2-6 用头插法创建单链表 分数 20 作者 朱晓龙 单位 西安邮电大学 Creat_LinkList()函数是使用头插法建立一个带头节点的单链表。函数须返回单链表的头指针,空链表须返回NULL。 函数接口定义: LinkList Creat_LinkList(); LinkList是函数返回的头指针类型。 裁判测试程序样例: #define FLAG -1 #include <stdio.h> #include <malloc.h> typedef int datatype; typedef struct node { datatype data; struct node *next; }LNode, *LinkList; LinkList Creat_LinkList(); void Print_LinkList(LinkList L);/*这里忽略函数实现部分 */ int main() { LinkList L; L = Creat_LinkList(); if(L == NULL) { printf("L=NULL,error!"); return 0; } Print_LinkList( L ); return 0; } /* 请在这里填写答案 */ 输入样例: 在这里给出一组输入。例如: 1 2 3 4 5 -1 输出样例: 在这里给出相应的输出。例如: 5 4 3 2 1

``` LinkList Creat_LinkList() { LinkList L = (LinkList)malloc(sizeof(LNode)); // 创建头节点 L->next = NULL; // 头节点的指针域置为 NULL datatype data; scanf("%d", &data); while (data != FLAG) { // FLAG 为结束标志 LNode* p = (LNode*)malloc(sizeof(LNode)); // 创建新节点 p->data = data; // 将数据存入新节点 p->next = L->next; // 将新节点插入到头节点之后 L->next = p; scanf("%d", &data); } return L; } ```

#include <stdlib.h>#include <stdio.h>#define N 10typedef struct list{ int data; struct list *next;} NODE;NODE *creat_list(int *a, int n){ NODE *head, *p, *q; head = (NODE *)malloc(sizeof(NODE)); head->next = NULL; q = head; for (int i = 0; i < n; i++) { p = (NODE *)malloc(sizeof(NODE)); p->data = a[i]; q->next = p; q = p; } q->next = NULL; return head;}void insNode(NODE *head, int x){ NODE *p, *q, *t; p = head; q = head->next; while (q != NULL && q->data < x) { p = q; q = q->next; } t = (NODE *)malloc(sizeof(NODE)); t->data = x; p->next = t; t->next = q;}void print(NODE *h){ NODE *p; p = h->next; while (p != NULL) { printf("%d ", p->data); p = p->next; } printf("\n");}int main(){ int i, j, x, a[N] = {1, 13, 25, 37, 9, 911, 133, 415, 147, 19}; NODE *head; head = creat_list(a, 10); scanf("%d", &x); insNode(head, x); print(head); return 0;}这个没问题吗?

这个代码的主要功能是实现将一个无序数组转化为有序链表,并能够在有序链表中插入一个新的元素,最后输出整个有序链表。代码的主要逻辑和实现方式都没有问题,但是有两个小问题需要注意: 1. 在创建链表的时候,首先要创建一个头节点,但是头节点不应该存储任何数据,因此应该将头节点的data域设为0或者其他一个无意义的值,而不是随便malloc一个节点。 2. 在插入新节点的时候,如果插入的节点比链表中所有节点的值都要小,那么新节点应该作为头节点的后继节点,而不是作为头节点本身。因此应该在while循环结束后,判断一下是否需要将新节点作为头节点的后继节点。 下面是修改后的代码: ``` #include <stdlib.h> #include <stdio.h> #define N 10 typedef struct list{ int data; struct list *next; } NODE; NODE *creat_list(int *a, int n){ NODE *head, *p, *q; head = (NODE *)malloc(sizeof(NODE)); head->data = 0; // 头节点不存储任何数据 head->next = NULL; q = head; for (int i = 0; i < n; i++) { p = (NODE *)malloc(sizeof(NODE)); p->data = a[i]; q->next = p; q = p; } q->next = NULL; return head; } void insNode(NODE *head, int x){ NODE *p, *q, *t; p = head; q = head->next; while (q != NULL && q->data < x) { p = q; q = q->next; } t = (NODE *)malloc(sizeof(NODE)); t->data = x; p->next = t; t->next = q; if (head->next == NULL || x < head->next->data) { head->next = t; } } void print(NODE *h){ NODE *p; p = h->next; while (p != NULL) { printf("%d ", p->data); p = p->next; } printf("\n"); } int main(){ int i, j, x, a[N] = {1, 13, 25, 37, 9, 911, 133, 415, 147, 19}; NODE *head; head = creat_list(a, 10); scanf("%d", &x); insNode(head, x); print(head); return 0; } ``` 希望能对你有所帮助!

相关推荐

#pragma GCC optimize ("O3") #pragma pack (16)//所有的存储都是以16个字节为单位的 #include <stdio.h> #include <stdlib.h> #include <string.h> #define tolower(c) (c>='A'&&c<='Z')?c-'A'+'a':c #define DATA 5200000 #define SIZE 1000005 int trie[4200000][26]; typedef struct node { int cnt; int logo; struct node *child[26]; } Node; Node *root; char str[35000000]; typedef struct word { char wor[85]; int cnt; } Word; Word w[300000]; struct node *creat() { Node *Root = (Node *)malloc(sizeof(Node)); Root->logo = 0; Root->cnt = 0; for (int i = 0; i < 26; i++) { Root->child[i] = NULL; } return Root; } void insert(Node *root, char *word, int flag) { struct node *leaf = root; for (int i = 0; word[i] != '\0'; i++) { int index = word[i] - 'a'; if (!leaf->child[index]) { leaf->child[index] = creat(); } leaf = leaf->child[index]; } if (leaf->logo != -1) leaf->logo = flag; leaf->cnt++; } int count = 0; void dfs(Node *leaf, char *word, int level) { if (leaf->logo == 1) { word[level] = '\0'; strcpy(w[count++].wor, word); w[count - 1].cnt = leaf->cnt; } for (int i = 0; i < 26; i++) { if (leaf->child[i]) { word[level] = i + 'a'; dfs(leaf->child[i], word, level + 1); } } } int cmp(const void *p1, const void *p2) { Word *v1, *v2; v1 = (Word *)p1; v2 = (Word *)p2; if (v1->cnt != v2->cnt) return v2->cnt - v1->cnt; else return strcmp(v1->wor, v2->wor); } int main(int argc, char *argv[]) { char s[1024]; int temp; int n, m;//读入n,m; //n = atoi(argv[1]); //m = atoi(argv[2]); scanf("%d%d", &n, &m); //读入stopwords中的元素,并令末序数组值为0,即该单词不计入 root = creat(); FILE *stopwords = fopen("stopwords.txt", "r"); while (fscanf(stopwords, "%s", s) != EOF) { insert(root, s, -1); } int cnt; FILE *article = fopen("article.txt", "r"); cnt = fread(str, sizeof(char), 35000000, article); char word[85]; int w_cnt = 0; for (int i = 0; i < cnt; i++) { char c = tolower(str[i]); if (c >= 'a' && c <= 'z') { word[w_cnt++] = c; } else { word[w_cnt] = '\0'; p = 0; w_cnt = 0; if (strlen(word) > 0) { insert(root, word, 1); } }//对article中的所有单词进行计数 } dfs(root, word, 0); qsort(w, count, sizeof(w[0]), cmp); printf("%s", w[0].cnt); return 0; }

#include <stdio.h> #include <stdlib.h> 访问标志向量是全局量 void DFSTraverse(ALGraph *G) { //深度优先遍历以邻接表表示的图 G,而以邻接矩阵表示 G 时,算法完全与 int i; for(i=0;i<G->n;i++) visited[i]=FALSE; //标志向量初始化 for(i=0;i<G->n;i++) if(!visited[i]) //vi 未访问过 DFS(G,i); //以 vi 为源点开始 DFS 此相同 搜索 }//DFSTraverse //(2)邻接表表示的深度优先搜索算法 void DFS(ALGraph *G,int i){ //以 vi 为出发点对邻接表表示的图 G 进行深度优先搜索 EdgeNode *p; printf("visit vertex:%c",G->adjlist[i].vertex);//访问顶点 vi visited[i]=TRUE; //标记 vi 已访问 p=G->adjlist[i].firstedge; //取 vi 边表的头指针 while(p){//依次搜索 vi 的邻接点 vj,这里 j=p->adjvex if (!visited[p->adjvex])//若 vi 尚未被访问 DFS(G,p->adjvex);//则以 Vj 为出发点向纵深搜索 p=p->next; //找 vi 的下一邻接点 } }//DFS #define MaxVertexNum 5 #define m 5 #define NULL 0 typedef struct node { int adjvex; struct node *next; }JD; typedef struct tnode { int vexdata; JD *firstarc; }TD; typedef struct { TD ag[m]; int n; }ALGRAPH; void DFS(ALGRAPH *G,int i); void creat(ALGRAPH *G) {int i,m1,j; JD *p,*p1; printf("please input the number of graph\n"); scanf("%d",&G->n); for(i=0;i<G->n;i++) {printf("please input the info of node %d",i); scanf("%d",&G->ag[i].vexdata); printf("please input the number of arcs which adj to %d",i); scanf("%d",&m1); printf("please input the adjvex position of the first arc\n"); p=(JD *)malloc(sizeof(JD)); scanf("%d",&p->adjvex); p->next=NULL; G->ag[i].firstarc=p; p1=p; for(j=2 ;j<=m1;j++) {printf("please input the position of the next arc vexdata\n"); p=(JD *)malloc(sizeof(JD)); scanf("%d",&p->adjvex); p->next=NULL; p1->next=p; p1=p;} } } int visited[MaxVertexNum]; void DFSTraverse(ALGRAPH *G) { int i; for(i=0;i<G->n;i++) visited[i]=0; for(i=0;i<G->n;i++) if(!visited[i]) DFS(G,i); }/*DFSTraverse */ void DFS(ALGRAPH *G,int i){ JD *p; printf("visit vertex:%d->",G->ag[i].vexdata); visited[i]=1; /*标记 vi 已访问 */ p=G->ag[i].firstarc; /*取 vi 边表的头指针*/ while(p){/*依次搜索 vi 的邻接点 vj,这里 j=p->adjvex*/ if (!visited[p->adjvex])/*若 vi 尚未被访问 */ DFS(G,p->adjvex);/*则以 Vj 为出发点向纵深搜索 */ p=p->next; } }/*DFS */ main() { ALGRAPH *G; printf("下面以临接表存储一个图;\n"); creat(G); printf("下面以深度优先遍历该图 \n"); DFSTraverse(G); getch(); }

优化这段代码的运行时间#include<stdio.h> #include<stdlib.h> typedef struct node* DNode; struct node { int data; DNode prior; //前面数据地址 DNode next; //后面数据地址 }; //创建双向链表 void CreatNode(DNode *head) { DNode s; //新节点指针 char e; (*head) = (DNode)malloc(sizeof(struct node));//头结点 (*head)->prior = (*head); //初始头结点的前驱和后驱都指向自己 (*head)->next = (*head); printf("输入数据\n"); scanf("%c", &e); while (e!='\n') { s = (DNode)malloc(sizeof(struct node)); //新节点分配空间 s->data = e; s->prior = (*head); //新节点的prior连前一个结点 s->next = (*head)->next; //新节点的next连后边结点 (*head)->next->prior = s; //后一个结点的prior连新结点 (*head)->next = s; //新节点前面的next连新结点 scanf("%c", &e); } } //向后遍历输出 void PrintList1(DNode L) { DNode p; p = L; p = p->next; while (p != L) { printf("%c", p->data); p = p->next; } printf("\n"); } //向前遍历输出 void PrintList2(DNode L) { DNode p; p = L->prior; while (p != L) { printf("%c", p->data); p = p->prior; } printf("\n"); } //查找第i处数据的地址 DNode FindPosition(DNode L,int i) { int j = 0; DNode p = L; while (p->next != L&&j < i) { p = p->next; j++; } return p; } //插入 void InsertList(DNode L) { DNode s,p; //s为新结点 p为新节点前一个结点 int i; char e; printf("在第几处插入:\n"); scanf("%d", &i); getchar(); printf("插入什么数据:\n"); scanf("%c", &e); p = FindPosition(L, i-1); //新节点前一个结点地址 s = (DNode)malloc(sizeof(struct node));//申请新节点空间 s->data = e; s->prior = p; //新节点的prior连上前一个结点 s->next = p->next; //新节点的next连上后一个结点 p->next->prior = s; //新节点后的结点的prior连上新结点 p->next = s; //新节点前的结点的next连上新结点 } //删除 void DeleteList(DNode L){ DNode s,p; //s为新结点 p为要删除的结点 int i; printf("删除第几处的数据:\n"); scanf("%d", &i); p = FindPosition(L, i); //要删除结点的地址 p->prior->next = p->next; //要删除的结点的前一个结点的next,连上要删结点后的结点 p->next->prior = p->prior;//要删除结点的后一个结点的prior,连上要删结点的前一个结点 free(p); } int main() { DNode list; CreatNode(&list); //PrintList1(list); PrintList2(list); InsertList(list); PrintList2(list); DeleteList(list); PrintList2(list); }

最新推荐

recommend-type

6-10.py

6-10
recommend-type

基于机器学习的入侵检测系统+源码+说明.zip

基于机器学习的入侵检测系统+源码+说明.zip
recommend-type

matlab基于潜在低秩表示的红外与可见光图像融合.zip

matlab基于潜在低秩表示的红外与可见光图像融合.zip
recommend-type

4-5.py

4-5
recommend-type

基于tensorflow使用简单线性回归实现波士顿房价预测源码.zip

基于tensorflow使用简单线性回归实现波士顿房价预测源码.zip
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

实现实时数据湖架构:Kafka与Hive集成

![实现实时数据湖架构:Kafka与Hive集成](https://img-blog.csdnimg.cn/img_convert/10eb2e6972b3b6086286fc64c0b3ee41.jpeg) # 1. 实时数据湖架构概述** 实时数据湖是一种现代数据管理架构,它允许企业以低延迟的方式收集、存储和处理大量数据。与传统数据仓库不同,实时数据湖不依赖于预先定义的模式,而是采用灵活的架构,可以处理各种数据类型和格式。这种架构为企业提供了以下优势: - **实时洞察:**实时数据湖允许企业访问最新的数据,从而做出更明智的决策。 - **数据民主化:**实时数据湖使各种利益相关者都可
recommend-type

2. 通过python绘制y=e-xsin(2πx)图像

可以使用matplotlib库来绘制这个函数的图像。以下是一段示例代码: ```python import numpy as np import matplotlib.pyplot as plt def func(x): return np.exp(-x) * np.sin(2 * np.pi * x) x = np.linspace(0, 5, 500) y = func(x) plt.plot(x, y) plt.xlabel('x') plt.ylabel('y') plt.title('y = e^{-x} sin(2πx)') plt.show() ``` 运行这段
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。