Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def prog (char c, list l) {
- prog_helper(c, l, 0, [])
- }
- def prog_helper (char c, list l, int pos) {
- if(pos>=l.size) {
- break;
- }
- if(l.get(pos) is list) {
- // for every returned list, create 1 entry in result
- printCombination(prog_helper_sublist(c, l.get(pos), 0, []), l, pos)
- } else {
- // If the character to insert and the character in the list with the given position is the same, SKIP since it will be duplicate of the next one
- if(c != l.get(pos)) {
- print(c, l, pos)
- }
- }
- prog_helper (c, l, pos+1, result)
- }
- def prog_helper_sublist (char c, list subL, int pos, list result) {
- if(pos>=l.size) {
- return result;
- }
- if(l.get(pos) is list) {
- result.appendLists(prog_helper_sublist(c, l.get(pos), 0, []), pos)
- } else {
- // If the character to insert and the character in the list with the given position is the same, SKIP since it will be duplicate of the next one
- if(c != l.get(pos)) {
- result.append(c, l, pos);
- }
- }
- prog_helper_sublist(c, subL, pos+1, result)
- }
- def printCombination(list insertedSubList, list original, int pos) {
- // print original with element in pos replaced with insertedSubList
- }
- def print(char c, list original, int pos) {
- // print original with c inserted in position pos
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement