数据结构之队列
来源:互联网 发布:java choice用法 编辑:程序博客网 时间:2024/05/18 13:43
#include<stdio.h>#include<malloc.h>#include<string.h>struct user{int ino;char name[10];char password[10];struct user *nest;struct user *pre;};//遍历void searchall(struct user * head){struct user * temp=head;if (temp==0) {printf("空链表!\n");}while(1){printf("%d\t%s\t%s\n",temp->ino,temp->name,temp->password);if(temp->nest==head) break;temp=temp->nest;}}//查找int search(struct user *head,char *pfindname){struct user *temp=head;while(1){if(strcmp(temp->name,pfindname)==0){printf("%d\t%s\t%s\n",temp->ino,temp->name,temp->password);return 1;}if(temp->nest==head) break;temp=temp->nest;}return -1;}//出栈struct user* pop(struct user *head){struct user *temp=head;if (head->nest==head) { temp=0; printf("出栈成功!\n"); free(head);return temp;}temp=head->nest;head->pre->nest=head->nest;head->nest->pre=head->pre;free(head);printf("出队成功!\n"); return temp; }//入栈struct user *push(struct user *head,struct user *adduser){struct user * temp=head;struct user * pnew=NULL;if(head==NULL){pnew=(struct user *)malloc(sizeof(struct user ));*pnew=*adduser;pnew->nest=pnew;pnew->pre=pnew;temp=pnew;printf("入队成功!\n");return temp;}pnew=(struct user *)malloc(sizeof(struct user ));*pnew=*adduser;pnew->nest=pnew;pnew->pre=pnew;head->pre->nest=pnew;pnew->nest=head;pnew->pre=head->pre;head->pre=pnew;printf("入队成功!\n");return temp;}int main(){int icount=0;struct user *head=NULL;int i=0;int select=0;int iScanfResult;while(1){printf("------------------------------------\n"); printf("------------用户管理----------------\n"); printf("-------------2 遍历-----------------\n"); printf("-------------3 查找-----------------\n"); printf("-------------6 出队-----------------\n"); printf("-------------8 入队-----------------\n"); printf("-------------0 退出------------------\n"); printf("------------------------------------\n"); printf("\n"); while(1){printf("请选择:");iScanfResult=scanf("%d",&select);;if (iScanfResult>0) break;else{printf("请输入正确的数字!\n");fflush(stdin);}}switch(select){case 2:{//遍历searchall(head);}break;case 3:{char pfindname[10];//查找一个临时名字int ispfindname=0;int i=0;int flag=0;printf("请你输入一个你要查找的用户的名字\n"); scanf("%s",&pfindname);ispfindname=search(head,pfindname);if(-1==ispfindname){printf("没有找到\n");}}break;case 6:{//删除head=pop(head);}break;case 8:{struct user insertpuser;printf("请输入新的用户的ID\n");scanf("%d", &insertpuser.ino);printf("请输入新的用户的名字\n");scanf("%s",insertpuser.name); printf("请输入新的用户的密码\n");scanf("%s",insertpuser.password); head=push(head,&insertpuser);}break;case 0:{}break;}}return 0;}
0 0
- 数据结构之队列(链式队列)
- 数据结构之队列(数组队列)
- 数据结构之队列-顺序队列
- 数据结构之循环队列
- 数据结构之顺序队列
- 数据结构之链队列
- java数据结构之队列
- 数据结构之队列
- 数据结构复习之【队列】
- 内核数据结构之队列
- 数据结构之队列实例
- 数据结构学习之队列
- 复习数据结构之队列
- C 队列之数据结构
- 基础数据结构之队列
- 数据结构之队列
- 大话数据结构之队列
- 数据结构之循环队列
- poj 3162 WalkingRace 树形dp+线段树
- 【好程序员笔记分享】——文件和目录处理
- 4.18android键盘弹出方式
- 关于车上那几块屏幕的一点思考
- SVN上传文件静态库文件.a文件缺失解决方案
- 数据结构之队列
- 迷宫最短路
- 使用PLSQL Developer连接远程Oracle
- 一个帖子学会Android开发四大组件
- P2&P301 项目软件总结
- windows中删除没用的服务
- iOS 屏幕横竖屏切换问题
- android studio 增加依赖
- Poj 3667 Hotel 【线段树最左空区间】