Introduction of C. Learn to write and compile C codes in Linux, Windows and Mac OS X. Start with basics and ask your doubts CodesDope: Introduction of C. Learn to write and compile C codes in Linux, Windows and Mac OS X. Start with basics and ask your doubts.
Linked list is one of the most important data structures. We often face situations, where the data is dynamic in nature and number of data can’t be predicted or the number of data keeps changing during program execution. Linked lists are very useful in this type of situations.
The implementation of a linked list in C++ is done using pointers. You can go through the pointers chapter if you don’t have a strong grip over it. You can also practice a good number of questions from practice section.
A linked list is made up of many nodes which are connected in nature. Every node is mainly divided into two parts, one part holds the data and the other part is connected to a different node. It is similar to the picture given below.
Here, each node contains a data member (the upper part of the picture) and link to another node(lower part of the picture).
Notice that the last node doesn’t point to any other node and just stores NULL.
In C++, we achieve this functionality by using structures and pointers. Each structure represents a node having some data and also a pointer to another structure of the same kind. This pointer holds the address of the next node and creates the link between two nodes. So, the structure is something like:
The first data member of the structure (named node) is an integer to hold an integer and the second data member is the pointer to a node (same structure). This means that the second data member holds the address of the next node and in this way, every node is connected as represented in the picture above.
The picture representing the above structure is given below.
And the picture representing the linked list is:
So, if we have access to the first node then we can access any node of the linked list. For example, if ‘a’ is a node then a->next
is the node next to the ‘a’ (the pointer storing the address of the next node is named ‘next’).
Dev C++ Codes List Pdf
One thing you should notice here is that we can easily access the next node but there is no way of accessing the previous node and this is the limitation of singly linked list.
Coding up a linked list
You are now clear with the concepts of a linked list. Let’s code it up. The first part is to create a node (structure).
Now, we will create a class ‘linked_list’ which will contain all the functions and data members required for a linked list. This class will use the structure ‘node’ for the creation of the linked list.
The second and the most important part of a linked list is to always keep the track of the first node because access to the first node means access to the entire list. So, let’s call our first node as ‘ head’.
We have made two nodes – head and tail. We will store the first node in ‘head’ and the last node in ‘tail’. The constructor of the linked list is making both ‘head ’ and ‘ tail’ NULL because we have not yet added any element to our linked list and thus both are NULL.
Now, let’s create a function of adding a node to our linked list.
If you are not familiar with the ‘malloc’ function, then just read the dynamic memory allocation chapter.
node *tmp=new node
– We are allocating the space required for a node by the new operator. Now, ‘tmp’ points to a node (or space allocated for the node).
tmp->data = n – We are giving a value to the ‘data’ of ‘tmp’ as passed to the function.
tmp->next=NULL
– We have given the value to ‘data’ in the previous line and a value of the pointer ‘next’ (NULL) in this line and thus making our node ‘tmp’ complete.
The next part after the creation of a node is to join the nodes and create the linked list. We will first check if the ‘head’ is NULL or not. If the ‘head’ is NULL, it means that there is no linked list yet and our current node(tmp) will be the ‘head’.
if(head NULL)
{
head = tmp;
tail = tmp;
}
If ‘head’ is NULL, our current node (tmp) is the first node of the linked list and this it will be ‘head’ and ‘tail’ both (as it is also the last element right now).
If ‘head’ is not NULL, it means that we have a linked list and we just have to add the node at the end of the linked list.
else
{
tail->next = tmp;
tail = tail->next;
}
The new node (tmp) will go after the ‘tail’ and then we are changing the tail because the new node is the new ‘tail’.
Try to understand the code by allocating two to three nodes by above mechanism and you will get it.
Next:
Dev-C++ showing its updated UI and new variable browsing options | |
Developer(s) | Bloodshed Software until 2005, Orwell (Johan Mes) since 2011 |
---|---|
Stable release | |
Repository | |
Written in | Delphi |
Operating system | Microsoft Windows, Linux (alpha only) |
Type | Integrated development environment |
License | GNU General Public License |
Website | orwelldevcpp.blogspot.com www.bloodshed.net at the Wayback Machine (archived March 20, 2016) |
Usage |
Dev-C++ is a free full-featured integrated development environment (IDE) distributed under the GNU General Public License for programming in C and C++. It is written in Delphi.
It is bundled with, and uses, the MinGW or TDM-GCC 64bit port of the GCC as its compiler. Dev-C++ can also be used in combination with Cygwin or any other GCC-based compiler.[1]
Dev-C++ is generally considered a Windows-only program, but there are attempts to create a Linux version: header files and path delimiters are switchable between platforms.
Devpaks[edit]
An additional aspect of Dev-C++ is its use of DevPaks: packaged extensions on the programming environment with additional libraries, templates, and utilities. DevPaks often contain, but are not limited to, GUI utilities, including popular toolkits such as GTK+, wxWidgets, and FLTK. Other DevPaks include libraries for more advanced function use. Users of Dev-C++ can download additional libraries, or packages of code that increase the scope and functionality of Dev-C++, such as graphics, compression, animation, sound support and many more. Users can create Devpaks and host them for free on the site. Also, they are not limited to use with Dev-C++ - the site says 'A typical devpak will work with any MinGW distribution (with any IDE for MinGW)'.
Development status[edit]
From February 22, 2005 to June 2011 the project was not noticeably active, with no news posted nor any updated versions released. In a 2006 forum post, lead developer Colin Laplace stated that he was busy with real-life issues and did not have time to continue development of Dev-C++.[2]
There are two forks of Dev-C++ since then: wxDev-C++ and the Orwell version.
wxDev-C++ is a development team that has taken Dev-C++ and added new features such as support for multiple compilers and a RAD designer for wxWidgets applications.
On June 30, 2011 an unofficial version 4.9.9.3 of Dev-C++ was released by Orwell (Johan Mes), an independent programmer,[3] featuring the more recent GCC 4.5.2 compiler, Windows' SDK resources (Win32 and D3D), numerous bugfixes, and improved stability. On August 27, after five years of officially being in a beta stage, version 5.0 was released.[4] This version also has its own separate SourceForge[5] page since version 5.0.0.5, because the old developer isn't responding to combining requests. On July 2014, Orwell Dev-C++ 5.7.1 was released featuring the more recent GCC 4.8.1 which supports C++11.
Notable uses[edit]
On May 4, 2015, The Singapore Prime Minister Lee Hsien Loong posted his Sudoku solver program in C++ on Facebook. In his screen shot, he's using Microsoft Windows and Dev-C++ as his IDE.[6]
Dev C++ Codes Examples
See also[edit]
References[edit]
- ^'Bloodshed Software - Providing Free Software to the internet community'. bloodshed.net. Retrieved 8 September 2015.
- ^'Dev-C++'. sourceforge.net. Retrieved 8 September 2015.
- ^Orwell. 'Dev-C++ Blog'. orwelldevcpp.blogspot.com. Retrieved 8 September 2015.
- ^Orwell. 'Dev-C++ Blog'. orwelldevcpp.blogspot.com. Retrieved 8 September 2015.
- ^orwelldevcpp. 'Dev-C++'. SourceForge. Retrieved 8 September 2015.
- ^'Prime Minister of Singapore shares his C++ code for Sudoku solver'. Ars Technica. Retrieved 8 September 2015.
External links[edit]
- Official website
- Dev-C++ on SourceForge.net
- Dev-C++ Portable on SourceForge.net