Cody

# Problem 44486. Vector push

Solution 1453716

Submitted on 1 Mar 2018 by shimon zusmanovsky
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Pass
filetext = fileread('push.m'); assert(isempty(strfind(filetext, 'regexp')),'regexp hacks are forbidden')

2   Pass
v = [1, 2, 7]; x = []; [v, n] = push(v, x); v_correct = [1, 2, 7]; n_correct = 3; assert(isequal(v, v_correct)); assert(isequal(n, n_correct));

m = 1 k = 3 a = 0 b = 0 v = 1 2 7 n = 3

3   Pass
v = []; x = [5, 6, 8]; [v, n] = push(v, x); v_correct = [5, 6, 8]; n_correct = 3; assert(isequal(v, v_correct)); assert(isequal(n, n_correct));

m = 0 k = 0 a = 1 b = 3 v = 5 6 8 n = 3

4   Pass
v = []; x = [7; 3; 9; 4]; [v, n] = push(v, x); v_correct = [7; 3; 9; 4]; n_correct = 4; assert(isequal(v, v_correct)); assert(isequal(n, n_correct));

m = 0 k = 0 a = 4 b = 1 v = 7 3 9 4 n = 4

5   Pass
v1 = randi(10, 1, 5); x = 5; [v, n] = push(v1, x); v_correct = [v1, 5]; n_correct = 6; assert(isequal(v, v_correct)); assert(isequal(n, n_correct));

m = 1 k = 5 a = 1 b = 1 v = 10 2 2 8 8 5 n = 6

6   Pass
v = [ones(4, 1)]; x = [3, 5]; [v, n] = push(v, x); v_correct = [1; 1; 1; 1; 3; 5]; n_correct = 6; assert(isequal(v, v_correct)); assert(isequal(n, n_correct));

m = 4 k = 1 a = 1 b = 2 y = 3 5 v = 1 1 1 1 3 5 n = 6

7   Pass
v = [zeros(1, 4)]; x = [3; 0]; [v, n] = push(v, x); v_correct = [0, 0, 0, 0, 3, 0]; n_correct = 6; assert(isequal(v, v_correct)); assert(isequal(n, n_correct)); v = [8, 2]; x = []; [v, n] = push(v, x); v_correct = [8, 2]; n_correct = 2; assert(isequal(v, v_correct)); assert(isequal(n, n_correct));

m = 1 k = 4 a = 2 b = 1 w = 3 0 v = 0 0 0 0 3 0 n = 6 m = 1 k = 2 a = 0 b = 0 v = 8 2 n = 2

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!