Posts

Showing posts from 2017

Build and Flash OpenWrt for Raspberry Pi

Image
OpenWrt is an open source project for embedded operating system based on Linux, primarily used on embedded devices to route network traffic. [ 1 ] In this post, I will write about how to get the OpenWrt source, compile it for your Raspberry Pi board type and flash the SD card with the generated image. First of all, you need a Linux build environment installed with the requirements needed to build the OpenWrt. I use Ubuntu 14.04. In the market, there are 4 types of Raspberry Pi boards. Type 1, 2, 3 and Zero. OpenWrt's latest trunk branch supports all of these types. I will go through trunk. Check out the source: git clone git://github.com/openwrt/openwrt.git This will create a directory called "openwrt" in your current directory. Go inside this directory and run make package/symlinks command. msezgin@ubuntu:~/openwrt/make package/symlinks Now, we need to do the configuration before starting the build. msezgin@ubuntu:~/openwrt/make menuconfig ...

Intersection of Linked Lists

Image
In some cases 2 linked list can intersect each other. In the following diagram, you see that 2 NULL terminated singly linked lists are intersected at the node 5. In this implementation, we will find in which node the 2 lists are intersecting each other. The function will return the node address. We will use the helper functions form the previous post which add nodes to the lists, print the lists etc... Function which finds the intersection: /* * link_list_intersect() * Finds the intersection node of 2 lists. */ struct node * link_list_intersect ( struct node *list1, struct node *list2) { struct node *long_list; struct node *short_list; int diff = 0 ; /* * Get the lengths of the lists. */ int len1 = list_lenght_get(list1); int len2 = list_lenght_get(list2); /* * Find which list is long and which list is short * and find the absolute lenght difference. */ if (len1 >= len2) { diff = l...

Singly Linked List Implementation

In this post, you will see the implementation of a singly linked list. It is one of the main data structures in computer programming. A singly linked list consists of nodes which are bound to each other with their "next" pointers. A simple node is represented at least 2 fields. A "next" node pointer and a "data" field. /*   * node structure.   */ struct node { struct node *next; int data; }; Some of the basic methods of a linked list and node data structures are implemented below. Create a Node Method: /*   * node_create()   * Creates a node.   */ struct node *node_create( int data) {     struct node *n = malloc( sizeof ( struct node));     if (!n) {         printf( "Unable to allocate memory for node\n" );         return NULL ;     }     n->data = data;     n->next = NULL ; ...