数据结构大型实验的记录(done)
用平衡二叉树的知识实现用户登录系统模拟
基本思路:
类:AVLnode (树的节点类)
AVLtree (树的基本操作类 包括insert remove search 平衡树的4种旋转)
UserInfo(用户信息类)
决定还是按日期更新 这样更完整一点
12-15
昨天写到12点多,基本写完了AVL类,删除部分还有待完善,之后可能要补充平衡过程。
昨天写完类后想到具体的用户交互过程,想到一个节点里不仅要存用户名还要存密码,然后之前写类的时候一直是当一个nodeValue来写的,写到头昏脑胀有点晕以为要重新写一遍把nodeValue更新到两个了。今天想到了很简单的解决办法,只要在AVLnode类里加一个string password然后在每次insert完后返回insert的节点,再用节点指向它的password就可以了。
初步做了交互界面。
不是数据的问题,insert方法本身就有问题 可能不只是旋转上的错误
apple fhy1118
Apple 1110111
abc ABC4C
Aabc1 **2
cat 890
but happy
flower flower
trees 5678910
flowst 9087
but1 000000
flowar 080808
12-16
尼玛挑了半天旋转 本来没问题的都快被我调成有问题的了。格式也超优化 结果发现是insert里面p往上遍历写错
for(int i=0;i<count-2;i++)
p=newnode->parent;
发现的时候心中真的千万匹草泥马开始奔腾啊!!!!!!
但是成功构建以后很爽!!!!!!!
这尼玛大概就是程序猿的痛并快乐着了吧!!!!!!!!!!
贴上完整代码!!!
// AVLnode.h: interface for the AVLnode class.
//
////////////////////////////////////////////////////////////////////// #if !defined(AFX_AVLNODE_H__C8E651E6_0EA9_4808_848B_0CB927923FAE__INCLUDED_)
#define AFX_AVLNODE_H__C8E651E6_0EA9_4808_848B_0CB927923FAE__INCLUDED_ #if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <stddef.h>
#include <string>
using namespace std; class AVLnode
{
public:
string nodeValue;// node data
string password;
AVLnode *left, *right, *parent; // child pointers and pointer to the node's parent
AVLnode (const string item, AVLnode *lptr=NULL, AVLnode *rptr=NULL, AVLnode *pptr=NULL):
nodeValue(item), left(lptr), right(rptr), parent(pptr)
{}
public:
AVLnode(){password="";};
virtual ~AVLnode(){}; }; #endif // !defined(AFX_AVLNODE_H__C8E651E6_0EA9_4808_848B_0CB927923FAE__INCLUDED_)
AVLnode.h
// AVLtree.h: interface for the AVLtree class.
//
////////////////////////////////////////////////////////////////////// #if !defined(AFX_AVLTREE_H__36B69688_6A87_4949_A008_13138B14D185__INCLUDED_)
#define AFX_AVLTREE_H__36B69688_6A87_4949_A008_13138B14D185__INCLUDED_ #if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000 #include "AVLnode.h"
#include "tnodeShadow.h"
#include <iostream>
#include <iomanip>
using namespace std; class AVLtree
{
public:
AVLtree(); // constructor. initialize root to NULL and size to 0
~AVLtree(); // destructor
tnodeShadow *buildShadowTree(AVLnode *t, int level, int& column); void displayTree(int maxCharacters);
void deleteShadowTree(tnodeShadow *t);
AVLnode *insert(const string &item);
void remove(const string &item);
AVLnode *search(const string &item) const;
AVLnode *getRoot(); private:
AVLnode *root; // pointer to tree root
int treeSize; // number of elements in the tree
AVLnode *creatAVLNode(const string item, AVLnode *lptr, AVLnode *rptr, AVLnode *pptr); int depth(AVLnode *p)
{
int ldep=,rdep=,depval;
if(p==NULL)
depval=-;
else
{
ldep=depth(p->left);
rdep=depth(p->right);
depval=+(ldep>rdep?ldep:rdep);
}
return depval;
}; int balanceFactor(AVLnode *cur)
{
int ldep=,rdep=;
AVLnode *p=cur;
ldep=depth(p->left);
rdep=depth(p->right);
return (rdep-ldep);
}; void rightRotate(AVLnode *cur)
{
//cur is the middle one
if(cur->right!=NULL)
{
cur->parent->left=cur->right;
cur->right->parent=cur->parent;
}
else cur->parent->left=NULL; if(cur->parent->parent==NULL)
{
cur->parent->parent=cur;
cur->right=cur->parent;
cur->parent=NULL;
root=cur;
}
else
{
AVLnode *pr=cur->parent->parent;
cur->right=cur->parent;
cur->parent->parent=cur; cur->parent=pr;
if(cur->nodeValue>pr->nodeValue)
pr->right=cur;
else pr->left=cur;
}
}; void leftRotate(AVLnode *cur)
{
//cur is the middle one
if(cur->left!=NULL)
{
cur->parent->right=cur->left;
cur->left->parent=cur->parent;
}
else cur->parent->right=NULL; if(cur->parent->parent==NULL)
{
cur->parent->parent=cur;
cur->left=cur->parent;
cur->parent=NULL;
root=cur;
}
else
{
AVLnode *pr=cur->parent->parent;
cur->left=cur->parent;
cur->parent->parent=cur; cur->parent=pr;
if(cur->nodeValue>pr->nodeValue)
pr->right=cur;
else pr->left=cur;
}
}; void leftrightRotate(AVLnode *cur)
{
//cur is the third one
//全空
if(cur->left==NULL&&cur->right==NULL)
{
cur->parent->right=NULL;
cur->parent->parent->left=NULL;
}
//一边空 另一边最多一个
else if(cur->right==NULL)
{
cur->left->parent=cur->parent;
cur->parent->right=cur->left;
cur->parent->parent->left=NULL;
}
else if(cur->left==NULL)
{
cur->right->parent=cur->parent->parent;
cur->parent->parent->left=cur->right;
cur->parent->right=NULL;
}
//非空 挂在一边 另一边最多只有一个元素
else
{
cur->left->parent=cur->parent;
cur->parent->right=cur->left; cur->right->parent=cur->parent->parent;
cur->parent->parent->left=cur->right; }
AVLnode *pr=cur->parent->parent->parent; cur->right=cur->parent->parent;
cur->parent->parent->parent=cur; cur->parent->parent=cur;
cur->left=cur->parent; if(pr!=NULL)
{
cur->parent=pr;
if(cur->nodeValue<pr->nodeValue)
pr->left=cur;
else pr->right=cur;
}
else
{
cur->parent=NULL;
root=cur;
}
}; void rightleftRotate(AVLnode *cur)
{
//cur is the third one
//全空
if(cur->left==NULL&&cur->right==NULL)
{
cur->parent->left=NULL;
cur->parent->parent->right=NULL;
}
//一边空 另一边最多一个
else if(cur->left==NULL)
{
cur->right->parent=cur->parent;
cur->parent->left=cur->right;
cur->parent->parent->right=NULL;
}
else if(cur->right==NULL)
{
cur->left->parent=cur->parent->parent;
cur->parent->parent->right=cur->left;
cur->parent->left=NULL;
}
//非空 挂在一边 另一边最多只有一个元素
else
{
cur->right->parent=cur->parent;
cur->parent->left=cur->right; cur->left->parent=cur->parent->parent;
cur->parent->parent->right=cur->left; }
AVLnode *pr=cur->parent->parent->parent; cur->left=cur->parent->parent;
cur->parent->parent->parent=cur; cur->parent->parent=cur;
cur->right=cur->parent; if(pr!=NULL)
{
cur->parent=pr;
if(cur->nodeValue<pr->nodeValue)
pr->left=cur;
else pr->right=cur;
}
else
{
cur->parent=NULL;
root=cur;
}
} }; #endif // !defined(AFX_AVLTREE_H__36B69688_6A87_4949_A008_13138B14D185__INCLUDED_)
AVLtree.h
// menu.h: interface for the menu class.
//
////////////////////////////////////////////////////////////////////// #if !defined(AFX_MENU_H__A58647F3_F271_4C38_8097_A38DF9CA38CF__INCLUDED_)
#define AFX_MENU_H__A58647F3_F271_4C38_8097_A38DF9CA38CF__INCLUDED_ #if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "AVLtree.h"
#include <fstream>
#include <stack>
using namespace std; class menu
{
public:
menu();
virtual ~menu();
void select();
void menuInsert();
void menuLogin();
void menulogsuccess(AVLnode *login);
void menuChange(AVLnode *login);
void menuDelete(AVLnode *login);
void menuexit(); private:
AVLtree tree;
}; #endif // !defined(AFX_MENU_H__A58647F3_F271_4C38_8097_A38DF9CA38CF__INCLUDED_)
menu.h
// menu.cpp: implementation of the menu class.
//
////////////////////////////////////////////////////////////////////// #include "menu.h" //////////////////////////////////////////////////////////////////////
// Construction/Destruction
////////////////////////////////////////////////////////////////////// menu::menu()
{
ifstream f;
f.open("1.txt");
string id,pass;
while(!f.eof())
{
f>>id>>pass;
AVLnode *t=tree.insert(id);
t->password=pass;
}
f.close();
} menu::~menu()
{ }
void menu::select()
{
cout<<"--------------------------------------------------------------------------------\n";
cout<<" welcome \n";
cout<<"--------------------------------------------------------------------------------\n";
cout<<"--------------------------------------------------------------------------------\n";
cout<<" 1.注册账号 \n\n";
cout<<" 2.登录账号 \n\n";
cout<<" 3.退 出 \n\n";
cout<<"--------------------------------------------------------------------------------\n";
cout<<"输入数字进行选择:";
int choice;
cin>>choice;
if(choice==)
menuInsert();
if(choice==)
menuLogin();
else
menuexit();
} void menu::menuInsert()
{
cout<<"--------------------------------------------------------------------------------\n";
cout<<" 注册账号 \n";
cout<<"--------------------------------------------------------------------------------\n";
bool exist=true;
string userId;
string npassword;
while(exist)
{
cout<<"请输入账号: ";
cin>>userId; AVLnode *judge=tree.search(userId);
if(judge==NULL) exist=false;
else cout<<"您输入的用户名已存在!\n";
}
AVLnode *cur=tree.insert(userId); cout<<"请输入密码: ";
cin>>npassword;
cur->password=npassword;
menuexit(); //更新注册后的用户信息 否则删除出错。
cout<<"--------------------------------------------------------------------------------\n";
cout<<" 注册成功! \n";
cout<<"--------------------------------------------------------------------------------\n";
cout<<"按1键返回上层...";
int num;
cin>>num;
if(num==)
select();
else
menuexit();
} void menu::menuLogin()
{
cout<<"--------------------------------------------------------------------------------\n";
cout<<" 登录账号 \n";
cout<<"--------------------------------------------------------------------------------\n";
string userId;
string npassword;
cout<<"请输入账号: ";
cin>>userId;
cout<<"请输入密码: ";
cin>>npassword;
AVLnode *login=tree.search(userId);
if(login==NULL)
{
cout<<"--------------------------------------------------------------------------------\n";
cout<<" 您输入的账号不存在! \n";
cout<<"--------------------------------------------------------------------------------\n";
cout<<"按下1键重新输入...\n";
int num;
cin>>num;
if(num==)
menuLogin();
else
menuexit();
}
else
{
if(login->password==npassword)
menulogsuccess(login);
else
{
cout<<"--------------------------------------------------------------------------------\n";
cout<<" 密码错误! \n";
cout<<"--------------------------------------------------------------------------------\n";
cout<<"按下1键重新输入...";
int num;
cin>>num;
if(num==)
menuLogin();
else
menuexit();
}
}
} void menu::menulogsuccess(AVLnode *login)
{
cout<<"--------------------------------------------------------------------------------\n";
cout<<" 登录成功! \n";
cout<<"--------------------------------------------------------------------------------\n";
cout<<"--------------------------------------------------------------------------------\n";
cout<<" 1.修改密码 \n\n";
cout<<" 2.删除账号 \n\n";
cout<<" 3.回主菜单 \n\n";
cout<<"--------------------------------------------------------------------------------\n";
cout<<"输入数字进行选择:";
int choice;
cin>>choice;
if(choice==) select();
if(choice==)
menuChange(login);
if(choice==)
menuDelete(login);
else
menuexit();
} void menu::menuChange(AVLnode *login)
{
cout<<"请输入新密码: ";
string npassword;
cin>>npassword; cout<<"请再次输入新密码: ";
string check;
cin>>check; if(check==npassword)
{
login->password=npassword;
cout<<"--------------------------------------------------------------------------------\n";
cout<<" 修改成功! \n";
cout<<"--------------------------------------------------------------------------------\n";
cout<<"按下1键返回登录...";
int num;
cin>>num;
if(num==)
menuLogin();
else
menuexit();
}
else
{
cout<<"--------------------------------------------------------------------------------\n";
cout<<" 两次输入不一致! \n";
cout<<"--------------------------------------------------------------------------------\n";
cout<<"按下1键返回修改 2键返回登录界面...";
int num;
cin>>num;
if(num==)
menuChange(login);
else if(num==)
menulogsuccess(login);
else menuexit();
}
} void menu::menuDelete(AVLnode *login)
{
cout<<"--------------------------------------------------------------------------------\n";
cout<<" 确认删除? \n";
cout<<"--------------------------------------------------------------------------------\n";
cout<<"按下1键确认 2键返回初始界面...";
int num;
cin>>num;
if(num==)
{
tree.remove(login->nodeValue);
cout<<"--------------------------------------------------------------------------------\n";
cout<<" 删除成功! \n";
cout<<"--------------------------------------------------------------------------------\n";
cout<<"按下1键返回初始界面...";
int n;
cin>>n;
if(n==)
select();
else
menuexit();
}
else if(num==)
select();
else menuexit();
} void menu::menuexit()
{
ofstream f;
f.open("1.txt");
string id,pass; stack<AVLnode*> s;
AVLnode *p=tree.getRoot();
while(p!=NULL||!s.empty())
{
while(p!=NULL)
{
s.push(p);
p=p->left;
}
if(!s.empty())
{
p=s.top();
id=p->nodeValue;
pass=p->password;
f<<id<<" "<<pass<<"\n"; s.pop();
p=p->right;
}
}
f.flush();
f.close(); }
menu.cpp
#include "AVLnode.h"
#include "AVLtree.h"
#include "menu.h"
#include <iostream>
using namespace std;
int main()
{ menu guest;
guest.select();
return ;
}
main.cpp
// AVLtree.cpp: implementation of the AVLtree class.
//
////////////////////////////////////////////////////////////////////// #include "AVLtree.h" //////////////////////////////////////////////////////////////////////
// Construction/Destruction
////////////////////////////////////////////////////////////////////// AVLtree::AVLtree()
{
root=NULL;
treeSize=;
} AVLtree::~AVLtree()
{
}
AVLnode *AVLtree::getRoot()
{
return root;
} AVLnode *AVLtree::creatAVLNode (const string item, AVLnode *lptr, AVLnode *rptr, AVLnode *pptr)
{
AVLnode *newNode;
// initialize the data and all pointers
newNode = new AVLnode (item, lptr, rptr, pptr);
return newNode;
} void AVLtree::displayTree(int maxCharacters)
{
string label;
int level = , column = ;
int colWidth = maxCharacters + ; int currLevel = , currCol = ; if (treeSize == )
return; tnodeShadow *shadowRoot = buildShadowTree(root, level, column); tnodeShadow *currNode; queue<tnodeShadow *> q; q.push(shadowRoot); while(!q.empty())
{
currNode = q.front();
q.pop(); if (currNode->level > currLevel)
{
currLevel = currNode->level;
currCol = ;
cout << endl;
} if(currNode->left != NULL)
q.push(currNode->left); if(currNode->right != NULL)
q.push(currNode->right); if (currNode->column > currCol)
{
cout << setw((currNode->column-currCol)*colWidth) << " ";
currCol = currNode->column;
}
cout << setw(colWidth) << currNode->nodeValueStr;
currCol++;
}
cout << endl; deleteShadowTree(shadowRoot);
} void AVLtree::deleteShadowTree(tnodeShadow *t)
{
if (t != NULL)
{
deleteShadowTree(t->left);
deleteShadowTree(t->right);
delete t;
}
} AVLnode *AVLtree::insert(const string &item)
{
AVLnode *t=root,*newnode,*parent=NULL;
while(t!=NULL)
{
parent=t;
if(item==t->nodeValue)
return NULL;
else if(item<t->nodeValue)
t=t->left;
else
t=t->right;
}
newnode=creatAVLNode(item,NULL,NULL,parent);
if(parent==NULL)
root=newnode;
else if(item>parent->nodeValue)
parent->right=newnode;
else
parent->left=newnode;
treeSize++; int bf=,count=;
AVLnode *cur=newnode,*p=newnode;
while(bf>=-&&bf<=&&cur!=root)
{
cur=cur->parent;
count++;
bf=balanceFactor(cur);
} if(bf<-||bf>)
{
if(count==) ;
else
{
for(int i=;i<count-;i++)
p=p->parent;
}
//all left
if(p->nodeValue<p->parent->nodeValue&&p->parent->nodeValue<cur->nodeValue)
rightRotate(p->parent); //all right
else if(p->nodeValue>p->parent->nodeValue&&p->parent->nodeValue>cur->nodeValue)
leftRotate(p->parent); //right left
else if(p->nodeValue<p->parent->nodeValue&&p->parent->nodeValue>cur->nodeValue)
rightleftRotate(p);
//left right
else if(p->nodeValue>p->parent->nodeValue&&p->parent->nodeValue<cur->nodeValue)
leftrightRotate(p);
}
return newnode;
} void AVLtree::remove(const string &item)
{
AVLnode *t=search(item);
if(t==NULL) return; //leaf node
else if(t->left==NULL&&t->right==NULL)
{
if(t==root)
root=NULL;
else if(t->nodeValue>t->parent->nodeValue)
t->parent->right=NULL;
else
t->parent->left=NULL;
}
//only left or right
else if(t->left==NULL)
{
if(t==root)
{
t->right->parent=NULL;
root=t->right;
}
else if(t->nodeValue>t->parent->nodeValue)
t->parent->right=t->right;
else
t->parent->left=t->right;
t->right->parent=t->parent;
}
else if(t->right==NULL)
{
if(t==root)
{
t->left->parent=NULL;
root=t->left;
}
else if(t->nodeValue>t->parent->nodeValue)
t->parent->right=t->left;
else
t->parent->left=t->left;
t->left->parent=t->parent;
}
//left && right
else
{
AVLnode *r=t;
if(t==root)
{
r=r->right;
while(r->left!=NULL)
r=r->left; r->left=t->left;
t->left->parent=r;
if(r->right==NULL&&r->parent!=root)
{
r->right=t->right;
t->right->parent=r;
r->parent->left=NULL;
}
else if(r->parent!=root)
{
r->parent->left=r->right;
r->right->parent=r->parent;
r->right=t->right;
t->right->parent=r;
} r->parent=NULL;
root=r; } else if(t->nodeValue>t->parent->nodeValue)
{
r=r->right;
while(r->left!=NULL)
r=r->left; if(r->parent!=t)
{
if(r->right==NULL)
r->parent->left=NULL;
else
{
r->right->parent=r->parent;
r->parent->left=r->right;
} r->right=t->right;
t->right->parent=r; r->parent=t->parent;
t->parent->right=r;
r->left=t->left;
t->left->parent=r;
}
else
{
r->parent=t->parent;
t->parent->right=r;
r->left=t->left;
t->left->parent=r;
} }
else
{
r=r->right;
while(r->left!=NULL)
r=r->left; if(r->parent!=t)
{
if(r->right==NULL)
r->parent->left=NULL;
else
{
r->right->parent=r->parent;
r->parent->left=r->right;
} r->right=t->right;
t->right->parent=r; r->parent=t->parent;
t->parent->left=r;
r->left=t->left;
t->left->parent=r;
}
else
{
r->parent=t->parent;
t->parent->left=r;
r->left=t->left;
t->left->parent=r;
} }
}
treeSize--;
delete t;
//平衡部分 } AVLnode *AVLtree::search(const string &item) const
{
AVLnode *t=root;
while(t!=NULL)
{
if(t->nodeValue==item) return t;
else if(item<t->nodeValue)
t=t->left;
else t=t->right; }
return NULL;
} tnodeShadow *AVLtree::buildShadowTree(AVLnode *t, int level, int& column)
{
tnodeShadow *newNode = NULL;
char text[];
ostrstream ostr(text,); if (t != NULL)
{
newNode = new tnodeShadow; tnodeShadow *newLeft = buildShadowTree(t->left, level+, column);
newNode->left = newLeft; ostr << t->nodeValue << ends;
newNode->nodeValueStr = text;
newNode->level = level;
newNode->column = column; column++; tnodeShadow *newRight = buildShadowTree(t->right, level+, column);
newNode->right = newRight;
} return newNode;
}
AVLtree.cpp
附调试时用的结构化打印树的函数
// tnodeShadow.h: interface for the tnodeShadow class.
//
////////////////////////////////////////////////////////////////////// #if !defined(AFX_TNODESHADOW_H__18034BAE_051F_4D57_91FF_BE10AFD37CDA__INCLUDED_)
#define AFX_TNODESHADOW_H__18034BAE_051F_4D57_91FF_BE10AFD37CDA__INCLUDED_ #if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000 #include <iomanip> // for setw()
#include <strstream> // for format conversion
#include <string> // node data formatted as a string
#include <queue>
#include <utility> using namespace std; class tnodeShadow
{
public:
string nodeValueStr; // formatted node value
int level,column;
tnodeShadow *left, *right; tnodeShadow ()
{}
};
#endif // !defined(AFX_TNODESHADOW_H__18034BAE_051F_4D57_91FF_BE10AFD37CDA__INCLUDED_)
tnodeShadow.h
第一次写这么完整的程序 运行的一刻真的好爽!
数据结构大型实验的记录(done)的更多相关文章
- 20172328《程序设计与数据结构》实验三 敏捷开发与XP实践报告
20172328<程序设计与数据结构>实验三 敏捷开发与XP实践报告 课程:<程序设计与数据结构> 班级: 1723 姓名: 李馨雨 学号:20172328 实验教师:王志强 ...
- 20172310 2017-2018-2 《程序设计与数据结构》实验三报告(敏捷开发与XP实践)
20172310 2017-2018-2 <程序设计与数据结构>实验三报告(敏捷开发与XP实践) 课程:<程序设计与数据结构> 班级: 1723 姓名: 仇夏 学号:20172 ...
- 20172301 《Java软件结构与数据结构》实验三报告
20172301 <Java软件结构与数据结构>实验三报告 课程:<Java软件结构与数据结构> 班级: 1723 姓名: 郭恺 学号:20172301 实验教师:王志强老师 ...
- 20172328《程序设计与数据结构》实验四 Android程序设计报告
20172328<程序设计与数据结构>实验四 Android程序设计报告 课程:<程序设计与数据结构> 班级: 1723 姓名: 李馨雨 学号:20172328 实验教师:王志 ...
- 20172301 《Java软件结构与数据结构》实验二报告
20172301 <Java软件结构与数据结构>实验二报告 课程:<Java软件结构与数据结构> 班级: 1723 姓名: 郭恺 学号:20172301 实验教师:王志强老师 ...
- 20172329 2018-2019 《Java软件结构与数据结构》实验三报告
20172329 2018-2019-2 <Java软件结构与数据结构>实验三报告 课程:<Java软件结构与数据结构> 班级: 1723 姓名: 王文彬 学号:2017232 ...
- 20172329 2018-2019-2 《Java软件结构与数据结构》实验二报告
20172329 2018-2019-2 <Java软件结构与数据结构>实验二报告 课程:<Java软件结构与数据结构> 班级: 1723 姓名: 王文彬 学号:2017232 ...
- 20172301 2017-2018-2 《程序设计与数据结构》实验一《Java开发环境的熟悉》实验报告
20172301 2017-2018-2 <程序设计与数据结构>实验一<Java开发环境的熟悉>实验报告 课程:<程序设计与数据结构> 班级: 1723 姓名: 郭 ...
- 20172301 《Java软件结构与数据结构》实验一报告
20172301 <Java软件结构与数据结构>实验一报告 课程:<Java软件结构与数据结构> 班级: 1723 姓名: 郭恺 学号:20172301 实验教师:王志强老师 ...
随机推荐
- zoj 3490
蛋都疼了,高了半天,Output Limit Exceeded 原来是输入的问题,我靠!!以后还是用输入输出c++好,这尼玛!!郁闷!!!!! #include<stdio.h> #inc ...
- [Jobdu] 题目1517:链表中倒数第k个结点
给出一个链表的头指针,要求找到倒数第k个节点,并输出这个节点的值 例子: 先看一个例子,链表为:1 2 3 4 5 6,倒数第2个节点就是5,倒数第一个节点就是6,以此类推.这里的链表有头节点,就是说 ...
- 1.1. chromium源代码分析 - chromiumframe - 介绍
本人能力有效,面对chromium庞大的代码就头大.还是先由前辈的chromiumFrame入手. 1. chromeFrame概貌 chromiumFrame是前辈的心血之作,以最小化的方式抽出ch ...
- [LeetCode]题解(python):115-Distinct Subsequences
题目来源: https://leetcode.com/problems/distinct-subsequences/ 题意分析: 给定字符串S和T,判断S中可以组成多少个T,T是S的子串. 题目思路: ...
- 【转】IOS 输入框被键盘遮盖的解决方法
做IOS开发时,难免会遇到输入框被键盘遮掩的问题.上网上搜索了很多相关的解决方案,看了很多,但是由衷的觉得太麻烦了. 有的解决方案是将视图上的所有的东西都添加到一个滚动视图对象( UIScrollVi ...
- cocos2dx ResolutionPolicy
FrameSize 参数,在游戏运行时,我们可以通过 CCEGLView::sharedOpenGLView()->getFrameSize();如果在手机上运行,那么不同分辨率将会得到不同的值 ...
- 让程序只运行一个实例(Delphi篇)(三种方法,其中使用全局原子的方法比较有意思)
Windows 下一个典型的特征就是多任务,我们可以同时打开多个窗口进行操作,也可以同时运行程序的多个实例,比如可以打开许多个资源管理器进行文件的移动复制操作.但有时出于某种考虑(比如安全性),我们要 ...
- Nginx工作原理和优化、漏洞(转)
查看安装了哪些模块命令: [root@RG-PowerCache-X xcache]# nginx/sbin/nginx -Vnginx version: nginx/1.2.3built by gc ...
- Cocos2d—X游戏开发之VS2010 控制台输出中文,模拟器中文乱码问题解决
首先,先解决第一个问题,我们使用VS2010开发的时候,调试的时候,中文打印出来都是乱码,这个问题很纠结. 如下图: CCLOG("cclog: 测试使用标签的自动换行和个别字体大写&quo ...
- android中文字高亮设置案例
在android中我们有时候需要对一些标示性的文字进行高亮[用不同的颜色显示],例如微博中的@**等等...这些特效是通过SpannableString这个类来实现的 思路是将要显示的string进行 ...