自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(15)
  • 收藏
  • 关注

原创 从尾到头打印单链表

#include <iostream> using namespace std; #include<stdlib.h> #include<stack> typedef struct node //节点结构 { struct node *next; int val; node(int m,struct node): val(m),next...

2018-08-16 13:38:30 256

原创 找出数组中重复的数字

题目:在一个长度为n的数组里的所有数字都在0到n-1的范围内。数组中某些数字是重复的,但不知道有几个数字重复了, 也不知道每个数字重复了几次。请找出数组中任意一个重复的数字。例如,如果输入长度为7的数组{2, 3, 1, 0, 2, 5, 3}, 那么对应的输出是重复的数字2或者3。

2018-08-14 15:02:22 175

原创 用两个队列实现一个栈

#include<iostream> #include<queue> using namespace std; class MyStack { public: void push(int val); void pop(); int gettop(); private: queue<int> que; }; void MyStack::pop()...

2018-08-14 11:02:53 114

原创 判断出栈顺序是否合法

#include<iostream> using namespace std; #include<stack> #include<string.h> class IsTrueSeq { public: IsTrueSeq():str1(NULL),str2(NULL){} bool JudgeLegal(char *push_str,char *pop...

2018-08-14 10:59:47 619

原创 用两个栈实现一个队列

#include<iostream> using namespace std; #include<stack> class MyQueue { public: void push(int val); void pop(); int gettop(); private: stack<int> dest; }; void MyQueue::pop() ...

2018-08-14 10:52:30 124

原创 如果单链表存在环,求环上节点的数量(设置一个计数器count)

int LoopNodeNum(Node *head) { Node *fast=NULL,*slow=NULL; fast=slow=head; while(fast!=NULL && fast->next!=NULL) { slow = slow->next; fast=fast->next; if(slow==fast) brea...

2018-08-14 10:45:08 537

原创 如果单链表有环,则找出环的入口点,将该节点返回,如果不存在环,则返回空

#include<iostream> using namespace std; class node { public: node(int v= 0):value(v),next(NULL){} int value; node *next; }; typedef class node Node; Node* findLoopStart(Node *head) { ...

2018-08-14 10:39:35 282

原创 C++中string类的实现(典型的几个重载函数)

#include <iostream> #include<string.h> using namespace std; class String { public: String( const char *str=NULL);//普通构造函数 String(const String &other); //拷贝构造函数 String& operato...

2018-08-14 10:23:35 1384

原创 判断单链表是否有环

typedef struct node//结点结构 { struct node* next; int data; }Node; bool IsHaveLoop(Node *head)//判断单链表是否有环 { if(head==NULL) return NULL; Node *slow=NULL,*fast=NULL; slow=...

2018-08-13 20:41:14 163

原创 单链表的划分:给定一个不带头节点的单链表和数值x,划分链表,使得所有小于x的节点排在大于等于x的节点之前(应该保留原来链表节点的相对顺序)

Node* partition(Node *head, int x) //链表的划分 { Node *s=NULL; if(head==NULL) return NULL; Node *p=head; Node *phead2=NULL,*phead1=NULL; Node *p1=NULL,*p2=NULL; while(p!=NULL) { if(p-&gt...

2018-08-13 20:34:44 1468

原创 查找不带头节点的单链表中倒数第k个节点,要求只能遍历一次链表

#include <iostream> using namespace std; #include<stdlib.h> typedef struct node { struct node *next; int val; node(int m,struct node): val(m),next(NULL) {} }Node; Node* Create() ...

2018-08-13 20:28:24 310

原创 找链表的中间结点(只能遍历一次链表)

Node* FindMiddleNode(Node *head)//快慢指针法 { Node *fast=head,*slow=head; if(fast==slow==NULL) return NULL; else if(fast->next==NULL) return fast;//说明只有一个节点 while(fast != NULL) { fast = ...

2018-08-13 20:24:30 192

原创 将不带头节点的单链表整体逆序

Node* List::Reverse1(Node *head { if(head == NULL) return NULL; if(head->next==NULL)//链表中只有一个节点 return head; Node *p1,*p2,*p3; p1=head; p2=head->next; head->next=NULL; p3=p2->...

2018-08-13 20:18:42 1115

原创 尾插法创建不带头节点的单链表

Node* Create()//尾插法创建单链表 { Node *p=NULL,*q=NULL; p=(Node *)malloc(sizeof(Node)); p->next=NULL; while(1==scanf("%d",&(p->val)))//当输入的字符不是数字时 循环结束 { count++; if(head==NULL) { he...

2018-08-13 20:15:27 3259

原创 在不带头节点的单链表中删除给定值x ,并返回该链表的头指针(该链表中可能有与x值相等的多个值)

Node * ListDeleteMore(Node *head,int x) { Node *p=head; Node *pf=NULL; Node *s=NULL; while(p!=NULL) { if(head->val==x) { p=p->next; head=p; } else if(p->val==x) { s=p...

2018-08-13 20:07:46 600

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除