#include <iostream>
#include <string.h>
using namespace std;
bool is_equal(char str[])
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif) ![](http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif) {
int len=strlen(str);
if (len==0)
return false;
else if (len%2==0)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
int mid=len/2;
bool flag=true;
int i,j;
for(i=0, j=len-1; i<mid; i++,j--)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
if (str[i]==str[j])
continue;
else
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
flag=false;
break;
}
}
return flag;
}
else
return false;
}
int main()
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif) ![](http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif) {
char str[]="helleh";
int return_val;
if (is_equal(str))
return_val=1;
else
return_val=0;
cout<<return_val<<endl;
}
//有序多项式加法
#include <iostream>
using namespace std;
struct Node
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif) ![](http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif) {
int coef;
int exp;
Node *next;
};
class MExpression
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif) ![](http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif) {
private :
Node *first;
public :
MExpression();
void InsertNode(int coef,int exp);
void DeleteNode(int exp);
void Add(MExpression me);
void PrintAll();
};
MExpression::MExpression()
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif) ![](http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif) {
first->next=NULL;
}
void MExpression::InsertNode(int coef,int exp)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif) ![](http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif) {
Node *s=new Node();
Node *p=first;
while(p->next!=NULL)
p=p->next;
s->coef=coef;
s->exp=exp;
s->next=p->next;
p->next=s;
}
void MExpression::DeleteNode(int exp)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif) ![](http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif) {
Node *p=first->next;
Node *q;
q=first;
while(p!=NULL)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
if (p->exp==exp) break;
q=p;
p=p->next;
}
q->next=p->next;
delete p;
}
void MExpression::Add(MExpression me)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif) ![](http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif) {
int i=0,j=0;
Node *p=first->next;
Node *q=me.first->next;
Node *pp,*qq;
pp=first;
qq=me.first;
while(p&&q)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
if (p->exp>q->exp)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
InsertNode(q->coef,q->exp);
q=q->next;
}
else if(p->exp==q->exp)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
p->coef+=q->coef;
p=p->next;
q=q->next;
}
else
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
p=p->next;
}
}
while(q)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
InsertNode(q->coef,q->exp);
q=q->next;
}
}
void MExpression::PrintAll()
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif) ![](http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif) {
cout<<"=== coef c exp e ==="<<endl;
Node *p=first->next;
while(p!=NULL)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) ![](http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif) {
cout<<p->coef<<" c "<<p->exp<<" e ";
p=p->next;
}
}
int main()
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif) ![](http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif) {
MExpression *me1=new MExpression();
MExpression *me2=new MExpression();
me1->InsertNode(1,1);
me1->InsertNode(2,2);
me1->InsertNode(3,3);
me1->InsertNode(4,4);
me2->InsertNode(1,2);
me2->InsertNode(2,3);
me2->InsertNode(3,4);
me2->InsertNode(4,5);
me1->Add(*me2);
me1->PrintAll();
}
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif) /**//*
循环双链表
*/
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
#include <iostream>
using namespace std;
struct Node
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif) ![](http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif) {
int data;
Node *next;
Node *prior;
};
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
class CycleDLList
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif) ![](http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif) {
private :
Node *first;
public:
CycleDLList();
void InsertNode(int data);
void DeleteNode(int data);
void PrintAll();
};
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
CycleDLList::CycleDLList()
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif) ![](http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif) {
first->prior=first;
first->next=first;
}
void CycleDLList::InsertNode(int data)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif) ![](http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif) {
Node *s=new Node();
s->data=data;
Node *p=first->next;
while(p->next!=first)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
p=p->next;
}
s->prior=p;
s->next=p->next;
p->next->prior=s;
p->next=s;
}
void CycleDLList::DeleteNode(int data)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif) ![](http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif) {
Node *p=first->next;
Node *q;
while(p!=first)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
if(p->data==data) break;
q=p;
p=p->next;
}
if (p!=first)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
q->next=p->next;
p->next->prior=q;
delete p;
}
}
void CycleDLList:: PrintAll()
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif) ![](http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif) {
Node *p=first->next;
Node *q=first->prior;
cout<<"p=p->next"<<endl;
while(p!=first)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) ![](http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif) {
cout<<p->data<<" ";
p=p->next;
}
cout<<endl;
cout<<"q=q->prior"<<endl;
while(q!=first)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) ![](http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif) {
cout<<q->data<<" ";
q=q->prior;
}
}
int main()
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif) ![](http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif) {
CycleDLList *cd=new CycleDLList();
cd->InsertNode(5);
cd->InsertNode(4);
cd->InsertNode(3);
cd->InsertNode(2);
cd->PrintAll();
cd->DeleteNode(2);
cd->PrintAll();
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
}
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
1 #include <iostream> 2 using namespace std; 3![](http://www.cppblog.com/Images/OutliningIndicators/None.gif) 4 struct Node 5![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif) { 6 int data; 7 Node *next; 8 }; 9 class CycleLinkList 10![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif) { 11 private : 12 Node *first; 13 public : 14 CycleLinkList(); 15 void InsertNode(int data); 16 void DeleteNode(int data); 17 void PrintAll(); 18 }; 19 20 CycleLinkList:: CycleLinkList() 21![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif) { 22 first=first->next; 23 } 24 void CycleLinkList::InsertNode(int data) 25![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif) { 26 Node *s=new Node(); 27 s->data=data; 28 Node *p=first; 29 if (p->next==first) 30![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) { 31 s->next=first->next; 32 first->next=s; 33 } 34 else 35![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) { 36 while(p->next!=first) p=p->next; 37 s->next=p->next; 38 p->next=s; 39 } 40 } 41 42 void CycleLinkList::DeleteNode(int data) 43![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif) { 44 Node *p=first->next; 45 Node *q=first->next; 46 while(p!=first) 47![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) { 48 if (p->data==data) break; 49 else 50![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) { 51 q=p; 52 p=p->next; 53 } 54 } 55 q->next=p->next; 56 delete p; 57 } 58 void CycleLinkList:: PrintAll() 59![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif) { 60 Node *p=first->next; 61 62 while(p!=first) 63![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) { 64 cout<<p->data<<" "; 65 p=p->next; 66 } 67 } 68 int main() 69![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif) { 70 CycleLinkList *cl=new CycleLinkList(); 71 cl->InsertNode(3); 72 cl->InsertNode(4); 73 cl->InsertNode(5); 74 cl->InsertNode(6); 75 cl->PrintAll(); 76 cl->DeleteNode(4); 77 cl->PrintAll(); 78 }
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif) public class SortDemo {
private int[] sortArray;
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) public SortDemo() {
sortArray=new int[8];
}
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) public void swap(int i,int j) {
int t=sortArray[i];
sortArray[i]=sortArray[j];
sortArray[j]=t;
}
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) public void insertArray(int pos,int val) {
sortArray[pos]=val;
}
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) public void selectSort() {
int t,tt;
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) for(int j=0;j<sortArray.length-1;j++) {
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) for(int i=j+1;i<sortArray.length;i++) {
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
if(sortArray[i]<sortArray[j]) swap(i,j);
}
}
}
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) public void bubbleSort() {
int exchange=sortArray.length;
int bound;
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) while(exchange!=0) {
bound=exchange-1;
exchange=0;
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) for(int i=0;i<bound;i++) {
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) if(sortArray[i]>sortArray[i+1]) {
swap(i,i+1);
exchange=i+1;
}
}
}
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
}
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) public void insertSort() {
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) for(int i=1;i<sortArray.length;i++) {
int temp=sortArray[i];
int j=i;
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) while(j>0&&temp<sortArray[j-1]) {
sortArray[j]=sortArray[j-1];
j--;
}
sortArray[j]=temp;
}
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
}
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) public void showResult() {
for(int i =0;i<sortArray.length;i++)
System.out.print(sortArray[i]+" ");
System.out.println("");
}
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) public static void main(String[] args) {
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
SortDemo so=new SortDemo();
so.insertArray(0,2);
so.insertArray(1,23);
so.insertArray(2,22);
so.insertArray(3,12);
so.insertArray(4,42);
so.insertArray(5,32);
so.insertArray(6,62);
so.insertArray(7,52);
so.showResult();
so.selectSort();
so.showResult();
so.bubbleSort();
so.showResult();
so.insertSort();
so.showResult();
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
}
}
CFileDialog( BOOL bOpenFileDialog, LPCTSTR
lpszDefExt = NULL, LPCTSTR lpszFileName
= NULL, DWORD dwFlags =
OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, LPCTSTR
lpszFilter = NULL, CWnd* pParentWnd =
NULL );
bOpenFileDialog
Set to TRUE to construct a File Open dialog box or
FALSE to construct a File Save As dialog box. // CFileDialog dlg(false,"TXT",NULL,NULL,"Text file(*.txt)|*.TXT|",NULL); 读取文件: virtual UINT Read( void* lpBuf,
UINT nCount ); throw( CFileException
); lpbuf缓冲区指针 nCount要读的长度 /*
int len=file.GetLength(); char *buffer=new char[len+1]; if(!buffer) { MessageBox("Allocating fail"); } else { try { file.Read(buffer,len); } catch(CFileException *e) { MessageBox("Reading file error"); file.Close(); e->Delete(); return ; } */ 获取当前时间:
current_time=CTime::GetCurrentTime(); str_year.Format("%d",current_time.GetYear()); str_month.Format("%d",current_time.GetMonth()); str_day.Format("%d",current_time.GetDay()); CString m_date=str_year+"-"+str_month+"-"+str_day;
单文档:利用画刷填充矩形,很简单 CRect rc(10,10,20,200); CBrush bru; bru.CreateHatchBrush (HS_BDIAGONAL ,RGB(0,0,255)); pDC->SelectObject (&bru); pDC->Rectangle (&rc); pDC->SelectObject (&bru); bru.DeleteObject (); 这是二维的,下面是三维的 三维的直方图,只是照我们手画圆柱体,在二维的基础上在上面和侧面加了平行四边 CRect rc(50,50,100,200); CBrush bru; CPoint r[4]; bru.CreateHatchBrush (HS_BDIAGONAL ,RGB(0,0,255)); pDC->SelectObject (&bru); pDC->Rectangle(&rc); //顶部四边形 r[0].x=50;r[0].y=50; r[1].x =100;r[1].y=0; r[2].x=150;r[2].y=0; r[3].x=100;r[3].y=50; pDC->Polygon (r,4); r[0].x=100;r[0].y=200; r[1].x =150;r[1].y=150; r[2].x=150;r[2].y=0; r[3].x=100;r[3].y=50; pDC->Polygon (r,4); pDC->SelectObject (&bru); bru.DeleteObject ();
置于ONDRAW函数里面(单文档):
CBitmap bm,*pbm; //定义位图对象 BITMAP bmMetric; //定义位图结构变量,保存位图的参数如宽,高 bm.LoadBitmap (IDB_BITMAP2); bm.GetBitmap (&bmMetric); //保存位图的参数到结构变量bmMetric
CDC memDC; //定义设备环境类对象 memDC.CreateCompatibleDC (pDC); //创建内存设备环境 pbm=memDC.SelectObject (&bm); //将位图选入设备环境 //将内存设备环境的位图传输到设备环境 pDC->BitBlt (0,0,bmMetric.bmWidth ,bmMetric.bmHeight ,&memDC,0,0,SRCCOPY); memDC.SelectObject (pbm); //恢复原设备环境对象 bm.DeleteObject (); memDC.DeleteDC();
|
|
| 日 | 一 | 二 | 三 | 四 | 五 | 六 |
---|
31 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 |
|
常用链接
留言簿(1)
随笔分类
随笔档案
搜索
最新评论
![](/images/xml.gif)
阅读排行榜
评论排行榜
|
|