Skip to content

Instantly share code, notes, and snippets.

#include<iostream>
#include<stack>
using namespace std;
typedef struct node{
int data;
node *next;
}node;
bool ispanlindrome (node *head){
# 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;
#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;
@songpu2015617
songpu2015617 / removemid
Created April 19, 2015 03:53
cc150 2.3
#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;
@songpu2015617
songpu2015617 / findkthtolast
Last active August 29, 2015 14:19
cc150 2.2
#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){
#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;
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;
}
#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)
#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;