Skip to content

Instantly share code, notes, and snippets.

//Reverse characters in a string:
void reverse(char* s)
{
int i;
char temp;
size_t l = strlen(s);
for (i = 0; i < (l/2); ++i) {
temp = s[i];
s[i] = s[l - i];
@alexprivalov
alexprivalov / array_to_double-linked_list.c
Created January 31, 2015 18:36
Write a “C” function to convert an array to a doubly-linked list.
#include <stdio.h>
#include <stdlib.h>
struct DoubleLinkedListItem //item of linked list
{
int field;
struct DoubleLinkedListItem *p_prev;
struct DoubleLinkedListItem *p_next;
};
@alexprivalov
alexprivalov / pointer_on_function.c
Created January 31, 2015 18:34
Write a “C” function that modifies each element of a user supplied array by applying a user-provided function to each element of an array of integers. The user-provided function can also accept parameters. Please provide a typedef for the user-provided function.
#include <stdio.h>
typedef void (*func_handler)(int *p_arr_item); //typedef for user defined function
void func_for_processing_array(int arr[], size_t arr_size, func_handler h);
void do_something_with_item(int *p_item);
int main(int argc, char **argv)
{
int test_arr[] = {23, 32, 43, 54, 2, 86, 90};
Queries for create all needed tables:
create table if not exists customers(customer_id integer primary key, customer_login text, customer_name text, unique(customer_login))
create table if not exists goods(good_id integer, good_description text, unique(good_id))
create table if not exists orders(order_id integer primary key, customer_id integer, good_id integer, unique(order_id, customer_id, good_id))
Queries to populate tables:
insert into customers(customer_login, customer_name) values("user_login1", "customer_name1")
insert into customers(customer_login, customer_name) values("user_login2", "customer_name2")
@alexprivalov
alexprivalov / work_with_struct.c
Created January 31, 2015 18:21
for test task
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ALIAS_QUANTITY 10
struct aliasID
{
char* alias; /* '\0'-terminated C string */
int specific_id;
#include <iostream>
using namespace std;
// 1. "lowest common denom"
class Widget
{
public:
virtual void draw() = 0;
};
class Subject
{
public:
virtual void execute() = 0;
};
class RealSubject: public Subject
{
string str;
public:
#include <iostream>
#include <vector>
using namespace std;
class Component
{
public:
virtual void traverse() = 0;
};
#include <iostream>
#include <string.h>
class Thousand;
class Hundred;
class Ten;
class One;
class RNInterpreter
{
#include <iostream>
using namespace std;
class Base
{
void a()
{
cout << "a ";
}
void c()