glxhyt

  C++博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  15 随笔 :: 0 文章 :: 4 评论 :: 0 Trackbacks

#

     摘要:                                 结果:  &...  阅读全文
posted @ 2010-09-26 21:11 郭龙 阅读(1509) | 评论 (0)编辑 收藏

     摘要:             日记 2010-4-5 关于MFC中的文本的编程: 简单是: 1,在CTestView中定义两个变量一个为CPoint的m_ptOrigin并设置为0;和 CString 的m_strLine的并设置为“”,在CTextView中。Cpp设置...  阅读全文
posted @ 2010-08-21 17:27 郭龙 阅读(1107) | 评论 (0)编辑 收藏

  1//#include "stack.h"
  2
  3#pragma once
  4#include <iostream>
  5
  6using namespace std;
  7class Stack
  8{
  9public:
 10    Stack(void);
 11    virtual ~Stack(void);
 12public:
 13    virtual void push (char c) = 0;
 14    virtual char pop () = 0;
 15}
;
 16
 17
 18//#include "ListStack.h"
 19
 20#pragma once
 21#include "stack.h"
 22#include <list>
 23
 24class ListStack :
 25    public Stack
 26{
 27    friend ostream& operator <<(ostream& out, ListStack &rht);
 28public:
 29    ListStack(void);
 30    ~ListStack(void);
 31
 32public:
 33    virtual void push (char c);
 34    virtual char pop();
 35
 36public:
 37
 38    list<char> m_ls;
 39    
 40}
;
 41
 42
 43//#include "stack.cpp"
 44
 45#include "StdAfx.h"
 46#include "Stack.h"
 47
 48Stack::Stack(void)
 49{
 50}

 51
 52Stack::~Stack(void)
 53{
 54}

 55
 56
 57// #include "ListStack.h"
 58
 59
 60#include "StdAfx.h"
 61#include "ListStack.h"
 62#include <iterator>
 63#include <list>
 64ListStack::ListStack(void)
 65{
 66}

 67
 68ListStack::~ListStack(void)
 69{
 70}

 71
 72void ListStack::push(char c)
 73{
 74
 75    m_ls.push_front(c);
 76}

 77
 78char ListStack::pop()
 79{
 80    char c =  m_ls.front();
 81        m_ls.pop_front();
 82    return c;
 83
 84}

 85ostream& operator <<(ostream &out, ListStack &rht)
 86{
 87    cout<<"stack element";
 88    list<char>::iterator beg = rht.m_ls.begin();
 89    list<char>::iterator end = rht.m_ls.end();
 90    for(; beg != end; beg -- )
 91
 92      out<<rht.pop();
 93
 94
 95    return out;
 96}

 97
 98
 99 
100
101//main.cpp
102
103// c++stack.cpp : 定义控制台应用程序的入口点。
104//
105
106#include "stdafx.h"
107#include "ListStack.h"
108#include <iterator>
109
110int _tmain(int argc, _TCHAR* argv[])
111{
112
113    ListStack liststack;
114    int num = 5;
115    while( num --)
116    {
117        char  temp;
118        cout<<"input alphat"<<endl;
119        cin>>temp;
120        liststack.push( temp );
121    }

122    
123      //num =5;
124     //cout<<liststack<<endl;
125    //while(num --)
126    //{
127
128    //   cout<<liststack.pop();
129
130    //}
131    list<char>::iterator beg = liststack.m_ls.begin();
132    list<char>::iterator end = liststack.m_ls.end();
133    for(; beg != end; ++ beg )
134        //cout<<liststack.pop()<<" ";
135        cout<<*beg <<endl;
136    
137    cout<<endl;
138    return 0;
139}

140
141
142
143
posted @ 2010-08-19 19:21 郭龙 阅读(238) | 评论 (0)编辑 收藏

     摘要:   1#ifndef _LOGING_  2#define _LOGING_  3#include <iostream>  4#include <string>  5#include <fstream> ...  阅读全文
posted @ 2010-08-19 19:18 郭龙 阅读(1634) | 评论 (0)编辑 收藏

     摘要:   著名的Josephus问题   据说著名犹太历史学家 Josephus有过以下的故事:在罗马人占领乔塔帕特後,39 个犹太人与Josephus及他的朋友躲到一个洞中,39个犹太人决定宁愿死也不要被人抓到,于是决定了一个自杀方式,41个人排成一个圆圈,由第1个人开始报数,每报数到第3人该人就必须自杀,然后再由下一个重新报数,直到所有人都自杀身亡为止。   然而Josephus ...  阅读全文
posted @ 2010-08-11 19:39 郭龙 阅读(362) | 评论 (0)编辑 收藏

仅列出标题
共2页: 1 2