Execute
Save
Share
Share link
share
share
share
Team
Public Teams
Comments
0
Created By:
Guest
Title:
Title
Description
Edit
Copy Link
Login
Email *
Password *
Login
OR
Create Account
Screen Name *
Email *
Password *
Retype Password *
Team Access Code
Register
Public CodeBins
HELP
--Select Theme--
Ambiance
Blackboard
Cobalt
Eclipse
Elegant
Erlang-Dark
Lesser-Dark
Monokai
Neat
Night
Rubyblue
Vibrant-Ink
Xq-Dark
New CodeBin
CodeBins Versions
03/12/2018- V.1
Recent CodeBins
View All CodeBins
02x01 - Stacks Using an Array //HEAD#include "stdio.h"#include "string.h"#include "stdlib.h"#include "math.h" //BODY int stackArr[100005]; int top = -1; //Stores the index of the topmost element on the stack void push(int x) { //- Insert an element onto the top of the stack stackArr[++top] = x; } int peek() // - Returns the topmost element on the stack { return stackArr[top]; } void pop() // - Removes an element from the top of the stack { top--; } int empty() //- Returns 1 if the stack is empty and 0 otherwise { if (top == -1) return 1; else return 0; } //TAIL int main() { int n; top = -1; scanf("%d", & n); for (int i = 0; i < n; i++) { int t, x; scanf("%d", & t); if (t == 1) { scanf("%d", & x); push(x); } else if (t == 2) { if (empty()) { printf("Invalid\n"); } else { pop(); } } else if (t == 3) { if (empty()) { printf("Invalid\n"); continue; } for (int j = top; j >= 0; j--) { printf("%d ", stackArr[j]); } printf("\n"); } else { if (empty()) { printf("Invalid\n"); continue; } printf("%d\n", peek()); } } return 0; } 02x02 - Stacks Using a LinkedList //HEAD#include "stdio.h"#include "string.h"#include "stdlib.h"#include "math.h" //BODY struct stackNode { int val; struct stackNode * next; }; typedef struct stackNode stackNode; stackNode * stackHead; // Head Pointer for stack LinkedList void push(int x) { // Insert an element onto the top of the stack stackNode * node = malloc(sizeof(stackNode)); node - > val = x; node - > next = NULL; if (stackHead == NULL) stackHead = node; else { node - > next = stackHead; stackHead = node; } } int peek() { // Returns the topmost element on the stack return stackHead - > val; } void pop() { // Removes an element from the top of the stack stackHead = stackHead - > next; } int empty() { // Returns 1 if the stack is empty and 0 otherwise if (stackHead == NULL) return 1; return 0; } //TAIL int main() { int n; stackHead = NULL; scanf("%d", & n); for (int i = 0; i < n; i++) { int t, x; scanf("%d", & t); if (t == 1) { scanf("%d", & x); push(x); } else if (t == 2) { if (empty()) { printf("Invalid\n"); } else { pop(); } } else if (t == 3) { if (empty()) { printf("Invalid\n"); continue; } stackNode * j = stackHead; while (j) { printf("%d ", j - > val); j = j - > next; } printf("\n"); } else { if (empty()) { printf("Invalid\n"); continue; } printf("%d\n", peek()); } } return 0; } The Freeman Problem#include < cmath > #include < cstdio > #include < vector > #include < iostream > #include < algorithm > using namespace std; int safe(int n, int k) { if (n == 1) return 1; return (safe(n - 1, k) + k - 1) % n + 1; } int main() { int n, k; cin >> n >> k; cout << safe(n, k); return 0; } 01x09 - Tisha and Orange Sorting#include < cmath > #include < cstdio > #include < vector > #include < iostream > #include < algorithm > using namespace std; int partition(int arr[], int l, int r) { int pivot = arr[r]; int i = l - 1; for (int j = l; j <= r - 1; j++) { if (arr[j] <= pivot) { i++; int temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } } int temp = arr[i + 1]; arr[i + 1] = arr[r]; arr[r] = temp; return (i + 1); } void Quicksort(int arr[], int l, int r) { if (l < r) { int p = partition(arr, l, r); cout << p << endl; for (int i = l; i <= r; i++) cout << arr[i] << " "; cout << endl; Quicksort(arr, l, p - 1); Quicksort(arr, p + 1, r); } } int main() { int n; cin >> n; int arr[n]; for (int i = 0; i < n; i++) cin >> arr[i]; Quicksort(arr, 0, n - 1); return 0; } 01x08 - Orange Partitioning#include < cmath > #include < cstdio > #include < vector > #include < iostream > #include < algorithm > using namespace std; int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ int n; cin >> n; int k = 0; int orange[n]; for (int i = 0; i < n; i++) cin >> orange[i]; for (int i = 0; i < n - 1; i++) if (orange[i] <= orange[n - 1]) { int temp = orange[i]; orange[i] = orange[k]; orange[k] = temp; k++; } int temp = orange[k]; orange[k] = orange[n - 1]; orange[n - 1] = temp; for (auto i: orange) cout << i << " "; return 0; }
Bottom of Page
In Head
On Load
On Ready
Setting
Validate
Copy
Format
Setting
Validate
Copy
Format
No Doc Type
HTML5
HTML 4.01 Transitional
HTML 4.01 Strict
HTML 4.01 Frameset
XHTML 1.1
XHTML 1.0 Transitional
XHTML 1.0 Strict
XHTML 1.0 Frameset
Copy
Format
Download
×
Code Description
×
Difference of Versions
HTML
CSS
JS
×
JS Error
×
CSS Error
Errors
Warnings
×
JavaScript Setting
JS Libraries:
Chrome Frame 1.0.3
Dojo 1.8.0
Dojo 1.7.3
Dojo 1.7.2
Ext Core 3.1.0
jQuery 1.8.0
jQuery 1.7.2
jQuery 1.6.0
jQuery 1.5.0
jQuery 1.4.4
jQuery 1.4.0
jQuery-min 1.7.2
jQueryUI-min 1.8.21
MooTools more-1.4.0.1-full
MooTools core-1.4.5-full
MooTools core-1.4.1-full
Prototype 1.7.1.0
script.aculo.us 1.9.0
SWFObject 2.2
Twitter Bootstrap 2.0.4
WebFont Loader 1.0.28
yui 3.5.1
User Libraries:
Upload File
JavaScript URL(s):
×
CSS Setting
CSS Libraries:
jQueryUI 1.8.21
Twitter Bootstrap 2.0.4
User Libraries:
Upload File
CSS URL(s):