qsort
uses quicksort
which in worst-case performance is O(n^2)
while Bitonic sort
worst-case is O(log^2(n))
. qsort
uses quicksort
which in worst-case performance is O(n^2)
while Bitonic sort
worst-case is O(log^2(n))
. unordered_map
in C++ permanently crippling it. So maybe the C approach of leaving it up to the implementers was the better choiceunordered_map
in C++ permanently crippling it. So maybe the C approach of leaving it up to the implementers was the better choice tone()
funcion tone()
funcion rdi, rsi, rdx, rcx, r8, and r9.
but i found for syscalls rcx is replaced by r10struct ListNode *mergeTwoLists(struct ListNode *list1, struct ListNode *list2) {
struct ListNode dummy; // Dummy head node.
struct ListNode *cur = &dummy;
// While there are elements in either list.
while (list1 && list2) {
if (list1->val < list2->val) {
cur->next = list1;
list1 = list1->next;
} else {
cur->next = list2;
list2 = list2->next;
}
cur = cur->next;
}
// Append the remaining elements of `list1` or `list2`.
cur->next = list1 ? list1 : list2;
return dummy.next;
}
struct ListNode *mergeTwoLists(struct ListNode *list1, struct ListNode *list2) {
struct ListNode dummy; // Dummy head node.
struct ListNode *cur = &dummy;
// While there are elements in either list.
while (list1 && list2) {
if (list1->val < list2->val) {
cur->next = list1;
list1 = list1->next;
} else {
cur->next = list2;
list2 = list2->next;
}
cur = cur->next;
}
// Append the remaining elements of `list1` or `list2`.
cur->next = list1 ? list1 : list2;
return dummy.next;
}
struct ListNode *mergeTwoLists(struct ListNode *list1, struct ListNode *list2) {
if (!list1) return list2;
if (!list2) return list1;
if (list1->val < list2->val) {
list1->next = mergeTwoLists(list1->next, list2);
return list1;
} else {
list2->next = mergeTwoLists(list1, list2->next);
return list2;
}
}
#include <stdbool.h>
bool validParentheses(const char *s) {
int CurP = 1;
while(*s) {
switch(*s++) {
case '(': CurP *= 2; break;
case ')': CurP /= 2; break;
}
}
return CurP == 1;
}
(edited)#include <stdbool.h>
bool validParentheses(const char *s) {
int CurP = 1;
while(*s) {
switch(*s++) {
case '(': CurP *= 2; break;
case ')': CurP /= 2; break;
}
}
return CurP == 1;
}
(edited)#include <stdbool.h>
bool validParentheses(const char *s) {
int CurP = 1;
while(*s) {
switch(*s++) {
case '(': CurP *= 2; break;
case ')': CurP /= 2; break;
}
}
return CurP == 1;
}
(edited)CurP <<= 1;
CurP >>= 1;
struct list {
int val;
struct list *next;
};
struct list *merge_inplace(struct list *a, struct list *b) {
struct list *result;
struct list **cur = &result;
while(a && b) {
if(a->val < b->val) {
*cur = a;
cur = &cur->next;
a = a->next;
} else {
*cur = b;
cur = &cur->next;
b = b->next;
}
}
if(a) {
*cur = a;
} else {
*cur = b;
}
return result;
}
use std::mem;
struct List {
val: i32,
next: Option<Box<List>>,
}
fn merge_inplace(mut a: Option<Box<List>>, mut b: Option<Box<List>>) -> Option<Box<List>> {
let mut result = None;
let mut cur: &mut Option<Box<List>> = &mut result;
loop {
match (a, b) {
(Some(mut a_inner), Some(mut b_inner)) => {
if a_inner.val < b_inner.val {
let a_next = mem::replace(&mut a_inner.next, None);
cur = &mut cur.insert(a_inner).next;
a = a_next;
b = Some(b_inner);
} else {
let b_next = mem::replace(&mut b_inner.next, None);
cur = &mut cur.insert(b_inner).next;
a = Some(a_inner);
b = b_next;
}
}
(Some(a_inner), None) => {
*cur = Some(a_inner);
break;
}
(None, Some(b_inner)) => {
*cur = Some(b_inner);
break;
}
(None, None) => break,
}
}
result
}
use std::mem;
// Definition for singly-linked list.
#[derive(PartialEq, Eq, Clone, Debug)]
pub struct ListNode {
pub val: i32,
pub next: Option<Box<ListNode>>,
}
impl ListNode {
#[inline]
fn new(val: i32) -> Self {
ListNode { next: None, val }
}
}
pub fn merge_two_lists(
list1: Option<Box<ListNode>>,
list2: Option<Box<ListNode>>,
) -> Option<Box<ListNode>> {
// Using a dummy head to simplify edge cases
let mut dummy = Box::new(ListNode::new(0));
let mut cur = &mut dummy;
// Two mutable references to list1 and list2
let mut l1 = list1;
let mut l2 = list2;
while l1.is_some() && l2.is_some() {
let next_node = if l1.as_ref().unwrap().val < l2.as_ref().unwrap().val {
// Temporarily replace l1 with None and take its value
mem::replace(&mut l1, None).unwrap().next
} else {
// Temporarily replace l2 with None and take its value
mem::replace(&mut l2, None).unwrap().next
};
// Append the smaller node to the result
cur.next = if l1.as_ref().unwrap().val < l2.as_ref().unwrap().val {
l1.take()
} else {
l2.take()
};
// Move the cur pointer forward
cur = cur.next.as_mut().unwrap();
// Move the list pointers (l1 or l2) forward
if l1.is_none() {
l1 = next_node;
} else {
l2 = next_node;
}
}
// Attach the remaining part of l1 or l2
cur.next = if l1.is_some() { l1 } else { l2 };
// Return the merged list, skipping the dummy head
dummy.next
}
use std::mem;
struct List {
val: i32,
next: Option<Box<List>>,
}
fn merge_inplace(mut a: Option<Box<List>>, mut b: Option<Box<List>>) -> Option<Box<List>> {
let mut result = None;
let mut cur: &mut Option<Box<List>> = &mut result;
loop {
match (a, b) {
(Some(mut a_inner), Some(mut b_inner)) => {
if a_inner.val < b_inner.val {
let a_next = mem::replace(&mut a_inner.next, None);
cur = &mut cur.insert(a_inner).next;
a = a_next;
b = Some(b_inner);
} else {
let b_next = mem::replace(&mut b_inner.next, None);
cur = &mut cur.insert(b_inner).next;
a = Some(a_inner);
b = b_next;
}
}
(Some(a_inner), None) => {
*cur = Some(a_inner);
break;
}
(None, Some(b_inner)) => {
*cur = Some(b_inner);
break;
}
(None, None) => break,
}
}
result
}
#include <stdbool.h>
bool validParentheses(const char *s) {
int CurP = 1;
while(*s) {
switch(*s++) {
case '(': CurP *= 2; break;
case ')': CurP /= 2; break;
}
}
return CurP == 1;
}
(edited)use std::mem;
struct List {
val: i32,
next: Option<Box<List>>,
}
fn merge_inplace(mut a: Option<Box<List>>, mut b: Option<Box<List>>) -> Option<Box<List>> {
let mut result = None;
let mut cur: &mut Option<Box<List>> = &mut result;
loop {
match (a, b) {
(Some(mut a_inner), Some(mut b_inner)) => {
if a_inner.val < b_inner.val {
let a_next = mem::replace(&mut a_inner.next, None);
cur = &mut cur.insert(a_inner).next;
a = a_next;
b = Some(b_inner);
} else {
let b_next = mem::replace(&mut b_inner.next, None);
cur = &mut cur.insert(b_inner).next;
a = Some(a_inner);
b = b_next;
}
}
(Some(a_inner), None) => {
*cur = Some(a_inner);
break;
}
(None, Some(b_inner)) => {
*cur = Some(b_inner);
break;
}
(None, None) => break,
}
}
result
}
*s++
increments the pointer#include <stdbool.h>
bool validParentheses(const char *s) {
int CurP = 1;
while(*s) {
switch(*s++) {
case '(': CurP *= 2; break;
case ')': CurP /= 2; break;
}
}
return CurP == 1;
}
(edited)#include <stdbool.h>
bool validParentheses(const char *s) {
int CurP = 1;
while(*s) {
switch(*s++) {
case '(': CurP *= 2; break;
case ')': CurP /= 2; break;
}
}
return CurP == 1;
}
(edited)use std::mem;
// Definition for singly-linked list.
#[derive(PartialEq, Eq, Clone, Debug)]
pub struct ListNode {
pub val: i32,
pub next: Option<Box<ListNode>>,
}
impl ListNode {
#[inline]
fn new(val: i32) -> Self {
ListNode { next: None, val }
}
}
pub fn merge_two_lists(
list1: Option<Box<ListNode>>,
list2: Option<Box<ListNode>>,
) -> Option<Box<ListNode>> {
// Using a dummy head to simplify edge cases
let mut dummy = Box::new(ListNode::new(0));
let mut cur = &mut dummy;
// Two mutable references to list1 and list2
let mut l1 = list1;
let mut l2 = list2;
while l1.is_some() && l2.is_some() {
let next_node = if l1.as_ref().unwrap().val < l2.as_ref().unwrap().val {
// Temporarily replace l1 with None and take its value
mem::replace(&mut l1, None).unwrap().next
} else {
// Temporarily replace l2 with None and take its value
mem::replace(&mut l2, None).unwrap().next
};
// Append the smaller node to the result
cur.next = if l1.as_ref().unwrap().val < l2.as_ref().unwrap().val {
l1.take()
} else {
l2.take()
};
// Move the cur pointer forward
cur = cur.next.as_mut().unwrap();
// Move the list pointers (l1 or l2) forward
if l1.is_none() {
l1 = next_node;
} else {
l2 = next_node;
}
}
// Attach the remaining part of l1 or l2
cur.next = if l1.is_some() { l1 } else { l2 };
// Return the merged list, skipping the dummy head
dummy.next
}
*s++
increments the pointer void a () {
int c = 0;
++++++++++++++c;
}
how do you like this code?next_pow_2:
dec eax
bsr rcx, rax
inc ecx
mov eax, 1
shl rax, cl
ret
struct listnode {
int val;
struct listnode *next;
}
struct listnode *
mergeTwoLists(struct listnode *a, struct listnode *b)
{
struct listnode **p[2] = { &a, &b };
struct listnode *n, *lh;
int i;
if (!a) return b;
if (!b) return a;
lh = a->val < b->val ? a : b; /* list head */
n = lh;
while (1) {
i = a->val < b->val;
n = n->next = *p[i];
if (!(*p = (*p)->next)) {
n->next = *p[i ^ 1];
break;
}
}
return lh;
}
dbg_dummies
variable. This makes the debug dummies more useful for debugging. Previously, the debug dummies were considered invalid clients, whereas they are now considered to be ingame, so they should behave mostly like real clients being connected to the server. The debug dummies also have correct client names now, e.g. "Debug dummy 42".
The game server code is cleaned...struct listnode {
int val;
struct listnode *next;
}
struct listnode *
mergeTwoLists(struct listnode *a, struct listnode *b)
{
struct listnode **p[2] = { &a, &b };
struct listnode *n, *lh;
int i;
if (!a) return b;
if (!b) return a;
lh = a->val < b->val ? a : b; /* list head */
n = lh;
while (1) {
i = a->val < b->val;
n = n->next = *p[i];
if (!(*p = (*p)->next)) {
n->next = *p[i ^ 1];
break;
}
}
return lh;
}
struct listnode *
mergeTwoLists(struct listnode *a, struct listnode *b)
{
struct listnode **p[2] = { &a, &b };
struct listnode *n, ln;
int i;
if (!a) return b;
if (!b) return a;
n = &ln;
while (1) {
i = a->val < b->val;
n = n->next = *p[i];
if (!(*p = (*p)->next)) {
n->next = *p[i ^ 1];
break;
}
}
return lh.next;
}
struct listnode *
mergeTwoLists(struct listnode *a, struct listnode *b)
{
struct listnode **p[2] = { &a, &b };
struct listnode *n, ln;
int i;
if (!a) return b;
if (!b) return a;
n = &ln;
while (1) {
i = a->val < b->val;
n = n->next = *p[i];
if (!(*p[i] = (*p[i])->next)) {
n->next = *p[i ^ 1];
break;
}
}
return ln.next;
}
struct listnode *
mergeTwoLists(struct listnode *a, struct listnode *b)
{
struct listnode **p[2] = { &a, &b };
struct listnode *n, ln;
int i;
if (!a) return b;
if (!b) return a;
n = &ln;
while (1) {
i = a->val < b->val;
n = n->next = *p[i];
if (!(*p[i] = (*p[i])->next)) {
n->next = *p[i ^ 1];
break;
}
}
return ln.next;
}
a
or b
is NULL
only they get changed and not on every iteration. 2^sizeof (int)
pairs thobool ValidParenthesesImpl(const char *pStr, unsigned Num)
{
switch(pStr[0])
{
case '(': return ValidParenthesesImpl(pStr + 1, Num + 1);
case ')': return Num > 0 && ValidParenthesesImpl(pStr + 1, Num - 1);
case '\0': return Num == 0;
default: return ValidParenthesesImpl(pStr + 1, Num);
}
}
bool ValidParentheses(const char *pStr)
{
return ValidParenthesesImpl(pStr, 0);
}
bool ValidParenthesesImpl(const char *pStr, unsigned Num)
{
switch(pStr[0])
{
case '(': return ValidParenthesesImpl(pStr + 1, Num + 1);
case ')': return Num > 0 && ValidParenthesesImpl(pStr + 1, Num - 1);
case '\0': return Num == 0;
default: return ValidParenthesesImpl(pStr + 1, Num);
}
}
bool ValidParentheses(const char *pStr)
{
return ValidParenthesesImpl(pStr, 0);
}
struct listnode {
int val;
struct listnode *next;
}
struct listnode *
mergeTwoLists(struct listnode *a, struct listnode *b)
{
struct listnode **p[2] = { &a, &b };
struct listnode *n, *lh;
int i;
if (!a) return b;
if (!b) return a;
lh = a->val < b->val ? a : b; /* list head */
n = lh;
while (1) {
i = a->val < b->val;
n = n->next = *p[i];
if (!(*p = (*p)->next)) {
n->next = *p[i ^ 1];
break;
}
}
return lh;
}
struct ListNode *mergeTwoLists(struct ListNode *list1, struct ListNode *list2) {
struct ListNode *head = (struct ListNode *)&list1;
struct ListNode **tail = &head;
while (list1 && list2) {
struct ListNode **min = list1->val < list2->val ? &list1 : &list2;
*tail = *min;
*min = (*min)->next;
tail = &((*tail)->next);
}
*tail = (struct ListNode *)((uintptr_t)list1 | (uintptr_t)list2);
return head->next;
}
((uintptr_t)list1 | (uintptr_t)list2)
nullptr
isn't guaranteed to translate to 0
if it is cast to some integer type/top5
for example
but get the game crash, the question is: where can i find NumCommands
probably this is where i missed/mode
that can enable teams to behave like team 0 with the added benefit of being able to manage it with /lock
and /invite
.
Tested with possible configurations such as sv_team
, sv_max_team_size
, sv_min_team_size
, sv_solo_server
.
Teams in "team 0 mode" can't use /save
, /load
or /practice
.
Closes #7380
Very little showcase:
https://github.com/ddnet/dd...