Skip to main content

Posts

Showing posts with the label Data Structure

Data Structures Using C for you

Data Structures Using C is a module book for you. After working through this module you should be able to create and use new and complex data types within C programs. Learning objectives After working through this module you should be able to:  Manipulate character strings in C programs.  Declare and manipulate single and multi-dimensional arrays of the C data types.  Create, manipulate and manage C pointers to data elements.  Create and manage complex data types in C.  Use unions to define alternate data sets for use in C programs.  Allocate memory to variables dynamically.  Manipulate characters and bits. Content of this module: Strings. Arrays. Pointers. Data definitions – Structures. Data definitions – Unions. Dynamic allocation of data Character and bit manipulation Download Data Structures Using C

What is a linked list and why linked list?

What is a linked list ?       A linked list is a linear data structure used to organize the data in the memory. As its name indicates linked list is a list of items called the 'NODE' linked using  pointers. A 'NODE' is a structure of List containing  two or more fields called the 'data /Info' field and 'Link/address' field. A linked list can be of any of the following type. L inked list used for collecting a sequence of objects, which allows efficient addition, removal and retrieval of elements from any position in the sequence. It is implemented as nodes, each of which contains a reference (i.e., a  link ) to the next and/or previous node in the sequence. Singly-Linked Lists Doubly-Linked Lists or Two way Linked List Circularly-Linked Lists Circularly-Doubly Linked Lists Fig: Simple Linked List. Why Linked lists ?             Let us consider an example of impl...

Queue and its Implementation using C++

Queue:  A queue is a container that implements the first in first out protocol. That means that the only accessible object in the container is the one among them that was inserted first. A good analogy is a group of people waiting in line of a ticket. The next one admitted is the person in the line who got here ahead of everyone else.   Common operations of queue on C++ are bool empty() Returns True if the queue is empty, and False otherwise. T & front() Returns a reference to the value at the front of a non-empty queue. There is also a constant version of this function,  const T & front() . void pop() Removes the item at the front of a non-empty queue. void push(const T &foo) Inserts the argument foo at the back of the queue. size_type size() Returns the total number of elements in the queue. Example: Stuck Implementation on C++  #include<iostream> #include<queue> using namespace std; template <class T> void print (const queue...

Stacks and its Implementation using C++

Stuck: Stack is a last in, first out (LIFO) abstract data type and data structure. It is a container that implements the last in first out (LIFO) Protocol. That means that the only accessible object in the container is the last one among them that was inserted. A stack of book is a good analogy: you can’t read any in the stack without first removing the books that are stacked on top of it. It has three fundamental operations: push, pop and stack top. When we using stack, we need a header file called stack. Example: Stuck Implementation on C++ #include<stack> using namespace std; int main(){ stack<string> s; s.push("Linux"); s.push("JAVA"); s.push("Oracle"); s.push("PHP"); cout<< "s.size() = " << s.size() << "\n"; while(!s.empty()){ cout << "s.top() = " <<s.top() <<"\n";    s.pop(); } cout<< "s.size() = " << s.s...