windows 命令记录
2012-02-25 22:21
155 查看
以下是我用c语言实现数据结构中的队列、
本文出自 “胡思旺” 博客,请务必保留此出处http://siwanghu.blog.51cto.com/10630140/1685570
#pragma once #ifndef _ELEMTYPE_H #define _ELEMTYPE_H typedef int Elemtype; #endif #ifndef _FUNCTIONPOINT_H #define _FUNCTIONPOINT_H typedef void(* Function)(Elemtype e); #endif #ifndef _STDLIB_H #define _STDLIB_H #include <stdlib.h> #endif #ifndef _QUEUE_H #define _QUEUE_H typedef struct Node { Elemtype Data; struct Node * p_next; }Node,* QueuePtr; typedef struct { QueuePtr p_front; QueuePtr p_rear; }Queue; #endif
#include "stdafx.h" bool InitQueue(Queue &Q); bool DestoryQueue(Queue &Q); bool ClearQueue(Queue &Q); bool QueueEmpty(const Queue &Q); int QueueLength(const Queue &Q); bool GetHead(const Queue &Q,Elemtype &e); bool EnterQueue(Queue &Q,Elemtype e); bool QuitQueue(Queue &Q,Elemtype &e); bool QueueTraverse(Queue &Q,Function CallBack);
#include "Queue.h" bool InitQueue(Queue &Q) { Q.p_front=(QueuePtr)malloc(sizeof(Node)); if(Q.p_front==NULL) return false; Q.p_rear=Q.p_front; Q.p_front->p_next=NULL; return true; } bool DestoryQueue(Queue &Q) { while (Q.p_front->p_next!=NULL) { Q.p_rear=Q.p_front->p_next; free(Q.p_front); Q.p_front=Q.p_rear; } free(Q.p_front); return true; } bool ClearQueue(Queue &Q) { if(Q.p_front==Q.p_rear) return false; else { QueuePtr temp=Q.p_front->p_next; while(temp->p_next!=NULL) { Q.p_rear=temp->p_next; free(temp); temp=Q.p_rear; } free(temp); Q.p_rear=Q.p_front; return true; } } bool QueueEmpty(const Queue &Q) { if(Q.p_front==Q.p_rear) return true; else return false; } int QueueLength(const Queue &Q) { if(Q.p_front==Q.p_rear) return 0; else { int Length=1; QueuePtr temp=Q.p_front->p_next; while(temp->p_next!=NULL) { Length++; temp=temp->p_next; } return Length; } } bool GetHead(const Queue &Q,Elemtype &e) { if(Q.p_front==Q.p_rear) { e=NULL; return false; } else { e=Q.p_front->p_next->Data; return true; } } bool EnterQueue(Queue &Q,Elemtype e) { QueuePtr temp=(QueuePtr)malloc(sizeof(Node)); temp->Data=e; Q.p_rear->p_next=temp; temp->p_next=NULL; Q.p_rear=temp; return true; } bool QuitQueue(Queue &Q,Elemtype &e) { if(Q.p_front==Q.p_rear) { e=NULL; return false; } else { QueuePtr temp=Q.p_front->p_next; e=temp->Data; Q.p_front->p_next=temp->p_next; if(temp==Q.p_rear) Q.p_rear=Q.p_front; free(temp); return true; } } bool QueueTraverse(Queue &Q,Function CallBack) { if(Q.p_front==Q.p_rear) return false; else { QueuePtr temp=Q.p_front->p_next; if(temp==Q.p_rear) { CallBack(temp->Data); return true; } else { while(temp->p_next!=NULL) { CallBack(temp->Data); temp=temp->p_next; } CallBack(temp->Data); return true; } } }
本文出自 “胡思旺” 博客,请务必保留此出处http://siwanghu.blog.51cto.com/10630140/1685570
相关文章推荐
- windows中 git 命令使用记录
- windows常用命令记录
- Windows下查询域名的DNS TXT记录的命令
- Windows命令记录
- windows之DNS7种资源记录和flushdns命令清除DNS缓存以及nslookup解析域名和ipconfig/all命令查看网络配置使用总结
- 用简单命令查看Windows上USB盘使用记录
- Windows Mongodb 安装记录+ 常用命令
- Windows下,在Git Bash中使用git log命令查看历史记录时,出现乱码的解决方法
- 记录windows网络和adb的一些命令
- MySql使用全记录5 -----解决Windows下用命令导入sql文件时"Failed to open file"的问题
- Windows常用批处理命令记录
- Windows命令记录
- windows下shutdown命令的方便小应用
- Windows程序设计问题记录
- 记录几个virtualbox命令学习一下
- windows下gvim使用及常见命令
- Windows操作系统的常用运行命令,修复系统最佳命令【在网上找的一篇也发给大家看下】
- Windows Regsvr32 命令
- 【收藏】Windows 8 Consumer Preview的108个运行命令及简要说明
- 使用Java控制Windows cmd命令的小经验