Last active
December 18, 2017 13:08
-
-
Save vovapolu/c810d3d3a86004322274781e3b18f195 to your computer and use it in GitHub Desktop.
Data structures 1
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
const int N = 100000; | |
const int K = 1000; | |
int cnt = 0; | |
int elems[N]; | |
int nxt[N]; | |
int lists[K]; | |
void add(int list, int new_elem) { | |
elems[cnt] = new_elem; | |
nxt[cnt] = -1; | |
int list_p = lists[list]; | |
if (list_p = -1) { | |
lists[list] = cnt; | |
cnt++ | |
} else { | |
while (nxt[list_p] != -1) { | |
list_p = nxt[list_p]; | |
} | |
nxt[list_p] = cnt; | |
cnt++; | |
} | |
} | |
void remove(int list, int idx) { | |
if (idx == 0) { | |
lists[list] = nxt[lists[list]]; | |
return; | |
} else { | |
int list_p = lists[list]; | |
while (nxt[list_p] != -1 && idx > 1) { | |
list_p = nxt[list_p]; | |
idx--; | |
} | |
if (idx == 1 && nxt[list_p] != -1) { | |
nxt[list_p] = nxt[nxt[list_p]]; | |
} | |
} | |
} | |
int join(int list1, int list2) { | |
??? | |
} |
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
const int N = 100000; | |
const int K = 1000; | |
int cnt = 0; | |
int elems[N]; | |
int nxt[N]; | |
int prev[N]; | |
int lists[K]; | |
void add(int list, int new_elem) { | |
elems[cnt] = new_elem; | |
nxt[cnt] = -1; | |
int list_p = lists[list]; | |
if (list_p = -1) { | |
lists[list] = cnt; | |
prev[cnt] = -1; | |
cnt++ | |
} else { | |
while (nxt[list_p] != -1) { | |
list_p = nxt[list_p]; | |
} | |
nxt[list_p] = cnt; | |
prev[cnt] = list_p; | |
cnt++; | |
} | |
} | |
void remove(int list, int idx) { | |
??? | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment