01 2024 档案
摘要:点击查看代码 //Binary tree traversal-- beadth-first and depth-first #include<iostream> #include<queue>//STL using namespace std; struct node { int data; nod
阅读全文
摘要:点击查看代码 //Binary tree traversal-- level-order traversal using queue #include<iostream> #include<queue>//STL using namespace std; struct node { int data
阅读全文
摘要:点击查看代码 #include<iostream> using namespace std; struct Node { int data; Node *left, *right; }; Node* newNode(int x) { Node* temp = new Node; temp->data
阅读全文
摘要:点击查看代码 #include<iostream> using namespace std; struct Node { int data; Node *left, *right; }; Node* newNode(int x) { Node* temp = new Node; temp->data
阅读全文
摘要:点击查看代码 #include<iostream> using namespace std; struct Node { int data; Node *left, *right; }; Node* newNode(int x) { Node* temp = new Node; temp->data
阅读全文
摘要:点击查看代码 #include<iostream> using namespace std; struct Node { int data; Node *left, *right;//注意声明格式 }; Node* newNode(int x) { Node* temp = new Node; te
阅读全文
摘要:点击查看代码 #include <iostream> using namespace std; struct Node { int data; Node* left; Node* right; }; Node* newNode(int x) { Node* temp = new Node; temp
阅读全文
摘要:尾递归(Tail Recursion)是一种特殊形式的递归,其特点是递归调用是函数的最后一个操作。在尾递归中,递归调用的返回值不需要进行额外的操作,而是直接返回给调用者。这种特殊的结构使得编译器有机会对递归调用进行优化,称为尾递归优化。 尾递归函数的特征是,在递归调用中,没有后续的计算步骤,直接将递
阅读全文
摘要:点击查看代码 //Inplementation of Binary Search Tree #include<iostream> using namespace std; struct bstnode { int data; bstnode* left; bstnode* right; }; /*b
阅读全文
摘要:点击查看代码 //Queue-Linked List Implementation #include<iostream> using namespace std; struct node { int data; node* next; }; node* front = NULL; node* rea
阅读全文
摘要:点击查看代码 //Infix to postfix conversion using stack #include<iostream> #include<stack>//stack from standard template library(STL) #include<string> using
阅读全文
摘要:点击查看代码 //Evaluation Of postfix Expression using stack #include<iostream> #include<stack>//stack from standard template library(STL) #include<string> u
阅读全文
摘要:点击查看代码 //Check for balanced parentheses using stack #include<iostream> #include<stack>//stack from standard template library(STL) #include<string> usi
阅读全文
摘要:点击查看代码 //Linked list reversal using stack #include<iostream> #include<stack>//stack from standard template library(STL) using namespace std; struct no
阅读全文
摘要:点击查看代码 //string reversal using stack #include<iostream> #include<stack>//stack from standard template library(STL) using namespace std; void reverse(c
阅读全文
摘要:点击查看代码 //Prime factorization of a number #include<iostream> #include<cmath> using namespace std; void primefactorization(int n) { for (int i = 2; i <=
阅读全文
摘要:点击查看代码 //Find all factors of a number #include<iostream> #include<cmath> using namespace std; void Factors(int n) { int* factors = new int[n+1](); for
阅读全文
摘要:点击查看代码 //Find all prime number upto n-Sieve of Eratosthenes #include<iostream> #include<cmath> using namespace std; void findprimes(int n) { int* prim
阅读全文
摘要:点击查看代码 //Verify a prime number-Trial division mothod #include<iostream> #include<cmath> using namespace std; int main() { int n; cin >> n; for (int i
阅读全文
摘要:点击查看代码 //Convert a number from decimal to binary #include<iostream> using namespace std; struct node { int data; node* next; }; node* A; void insert(i
阅读全文
摘要:点击查看代码 //Quick sort #include<iostream> using namespace std; int partition(int A[],int start,int end) { int pivot = A[end];//默认选取末尾为主元 int pIndex = sta
阅读全文
摘要:点击查看代码 //Stack-link list implementation #include<iostream> using namespace std; struct node { int data; node* next; }; node* top; void push(int x) { n
阅读全文
摘要:点击查看代码 //Merge sort #include<iostream> using namespace std; void merge(int L[], int R[], int A[], int nL, int nR) {//将两个已排序数组合并填入 int i = 0, j = 0, k
阅读全文
摘要:点击查看代码 //Insertion sort #include<iostream> using namespace std; void insertionsort(int A[], int n) { int value, hole;//value表示插入值,hole表示插入位置 for (int
阅读全文
摘要:点击查看代码 //Bubble sort #include<iostream> using namespace std; void bubblesort(int A[], int n) { for (int k = 1; k < n; k++) {//遍历n-1次,使索引1至索引n-1完成排序,索引
阅读全文
摘要:点击查看代码 //Selection sort #include<iostream> using namespace std; void selectionsort(int A[], int n) { for (int i = 0; i < n - 1; i++) {//从索引0开始排序至索引n-2
阅读全文
摘要:点击查看代码 //Stack-array based implementation #include<iostream> using namespace std; #define MAX_SIZE 101 int A[MAX_SIZE];//globle int top = -1;//globle
阅读全文
摘要:点击查看代码 //Doubly linked list #include<iostream> using namespace std; struct node { int data; node* next; node* prev; };//定义双向链表结构体 node* A; node* getne
阅读全文
摘要:点击查看代码 //Reverse a linked list using recursion #include<iostream> using namespace std; struct node { int data; node* next; }; node* A;//思考局部头指针如何递归 vo
阅读全文
摘要:点击查看代码 //Print linked list using recursion #include<iostream> using namespace std; struct node { int data; node* next; }; void print(node* p) { if (p
阅读全文
摘要:点击查看代码 //Reversse a linked list #include<iostream> using namespace std; struct node { int data; node* next; }; node* A; void reverse() { node* next;//
阅读全文
摘要:点击查看代码 //Delete d node at nth position #include<iostream> using namespace std; struct node { int data; node* next; }; node* A; void insert(int x) { no
阅读全文
摘要:点击查看代码 //Inserting a node at nth position #include<iostream> using namespace std; struct node { int data; node* next; }; node* A;//全局头指针 void insert(i
阅读全文
摘要:点击查看代码 //inserting a node at beginning,局部变量头指针版本2 #include<iostream> using namespace std; struct node { int data; node* next; }; void insert(int x, no
阅读全文
摘要:点击查看代码 //inserting a node at beginning,局部变量头指针版本1 #include<iostream> using namespace std; struct node { int data; node* next; }; node* insert(int x,no
阅读全文
摘要:点击查看代码 //inserting a node at beginning,全局变量头指针 #include<iostream> using namespace std; struct node { int data; node* next; }; node* A; void insert(int
阅读全文
摘要:点击查看代码 //遍历链表,将节点接到末端 #include<iostream> using namespace std; struct node { int data;//数据 node* next;//尾巴 };//定义节点结构体 node* A;//头指针固定,global variable,
阅读全文