m

// Linklist.h: interface for the Linklist class.
//
//

#if !defined(AFX_LINKLIST_H__4E62685D_4A8F_4C66_BAE4_54E8354E8F01__INCLUDED_)
#define AFX_LINKLIST_H__4E62685D_4A8F_4C66_BAE4_54E8354E8F01__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

class Linklist  
{
private:
	typedef struct Node{
		Node *prev,*next;
		char data;
		Node(int t):data(t),prev(NULL),next(NULL){}
	}node;
	node* head;
	node* cur;
	int len;
public:
	Linklist();
	virtual ~Linklist();
	void checkEmpty();
	bool empty() const ;
	void pop_back();
	void pop_front();
	char back();
	char front();
	int size();
	void push_front(char x);
	void push_back(char x);
};

#endif // !defined(AFX_LINKLIST_H__4E62685D_4A8F_4C66_BAE4_54E8354E8F01__INCLUDED_)

<pre name="code" class="cpp">// Linklist.cpp: implementation of the Linklist class.
//
//

#include "stdafx.h"
#include "G.h"
#include "Linklist.h"
#include "iostream"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//
// Construction/Destruction
//

 Linklist::Linklist()
{
	cur=head=new node(-1);
	len=0;
}

Linklist::~Linklist()
{

}

char Linklist::back()
{
    checkEmpty();
    return cur->data;
}

char Linklist::front()
{
    checkEmpty();
    return head->next->data;
}


void Linklist::checkEmpty()
{
    if(empty())
    {
		std::cout << "error" ;
    }
}

void Linklist::pop_back(){
	checkEmpty();
	cur=cur->prev;
    delete cur->next;
    cur->next=NULL;
    --len;
}

void Linklist::pop_front()
{
    checkEmpty();
    node* tmp=head->next;
    head->next=tmp->next;
    tmp->prev=head;
    delete tmp;
    --len;
}

void Linklist::push_front(char x){
	node* newNode = new node(x);
	head->next=newNode;
	newNode->prev=head;
	++len;
}

void Linklist::push_back(char x)
{
    node* newNode=new node(x);
    newNode->prev=cur;
    cur->next=newNode;
    cur=newNode;
    ++len;
}

bool Linklist::empty() const
{
    return len==0;
}

int Linklist::size(){
	return len;
}



 

void CGView::OnDraw(CDC* pDC)
{
	CGDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
	Midpoint_Line(100,100,500,500,RGB(255,0,0),pDC);

	Linklist l;
	l.push_back('1');
	l.push_back('2');
	l.push_back('3');
	pDC->TextOut(50,40,_T(l.back()));
	pDC->TextOut(50,80,_T(l.front()));

	l.push_front('0');
	pDC->TextOut(50,120,_T(l.front()));

	l.pop_back();
	pDC->TextOut(50,160,_T(l.back()));
}

// 画线函数
void CGView::Midpoint_Line(int x0,int y0,int x1,int y1,COLORREF color,CDC * pDC){
	int a,b,d1,d2,d,x,y;
	a=y0-y1,b=x1-x0,d=2*a+b;
	d1=2*a,d2=2*(a+b);
	x=x0,y=y0;
	pDC->SetPixel(x,y,color);
	while(x<x1){
		if(d<0) { x++,y++,d+=d2; }
		else { x++,d+=d1; }
		pDC->SetPixel(x,y,color);
	}
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值