This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
#include<stack> | |
using namespace std; | |
typedef struct node{ | |
int data; | |
node *next; | |
}node; | |
bool ispanlindrome (node *head){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# include <iostream> | |
# inclue <map> | |
using namespace std; | |
typedef struct node{ | |
int data; | |
node *next; | |
}node; | |
node* cyclelinklist(node *head){ | |
if (head=NULL) return NULL; | |
node *fast=head, *slow=head; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# include <iostream> | |
using namespace std; | |
typedef struct node{ | |
int data; | |
node *next; | |
}node; | |
node * addtwonumber(node*l1,node*l2){ | |
if (l1==NULL) return l2; | |
if (l2==NULL) return l1; | |
node *res, *pre=NULL; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
using namespace std; | |
typedef struct node{ | |
int data; | |
node *next; | |
}node; | |
node *partitionlist(node *head, int x){ | |
node *dummy = new node(); | |
dummy->next=head; | |
head=dummy; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
using namespace std; | |
typedef struct node{ | |
int data; | |
node *next; | |
}node; | |
void removemid(node *mid){ | |
if (mid==NULL||mid->next=NULL) return; | |
node*q=mid->next; | |
mid->data=q->data; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
using namespace std; | |
typedef struct node { | |
int data; | |
node *next; | |
}node; | |
node* findkthtolast(node *head, int k){ | |
if (head==NULL||k<1) return NULL; | |
node *fast=head, *slow=head; | |
while(k>0 && fast){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
void duplicate_list(node *head){ | |
if(head==NULL) return; | |
node *p, *q, *c=head; | |
while(c){ | |
p=c; q=c->next; | |
int d = c->data; | |
while(q){ | |
if(q->data==d){ | |
node *t = q; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void zero(int **a, int m, int n){ | |
bool row[m], col[n]; | |
memset(row, false, sizeof(row)); | |
memset(col, false, sizeof(col)); | |
for(int i=0; i<m; ++i) | |
for(int j=0; j<n; ++j) | |
if(a[i][j] == 0){ | |
row[i] = true; | |
col[j] = true; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
void swap(int &a, int &b){ | |
int t = a; | |
a = b; | |
b = t; | |
} | |
void transpose(int a[][4], int n){ | |
for(int i=0; i<n; ++i) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
using namespace std; | |
string compress(string s) { | |
string result; | |
for (int i = 0; i < s.size(); ) { | |
int j = i + 1; | |
char curr = s[i]; | |
while (j < s.size() && s[j] == curr) ++j; |
NewerOlder