Monday, March 23, 2020

Dynamic Memory Allocation in C++


C++ Dynamic Memory Allocation is different from that seen in the C. While C uses functions like malloc(), calloc(), realloc() and free() to handle operations based on DMA, C++ also uses all the 4 functions in addition to 2 different operators called new and delete to allocate memory dynamically.

These statements are indicative of the fact that DMA is implemented by the programmer itself. C++ lacks the feature of a garbage collector which automatically helps to free up unnecessary memory space occupied by stagnant garbage values.

It is important to note that the memory is dynamically allocated on the Heap. The non-static memory and local variables get memory allocated on Stack.

ABOUT GENERALIZED LINK LIST

As we are going to implement Family tree using Generalized link list,Let us understand what a generalized link list is and how we are going to implement it.



  •  Generalized Linked List L, is defined as a finite sequence of elements in which  each element can be atom or group of atom.
  • A linked list is a linear data structure, in which the elements are not stored at contiguous memory locations .

The elements in a linked list are linked using pointers as shown below




A generalized link list consists of some extra fields such a as Flag,down pointer.
1)Flag is used to indicate the type of information stored by the node.
2)Down pointer is used if any element in the list is sub list.
A general node structure of generalized link list is as  shown below:
we can assign values in flag as per our convenience.
e.g Flag=0 implies node consist of data
      Flag=1 implies next pointer
     Flag=2 implies down pointer

Given below is a structure of general lists consisting of sub list.


1)In above example,in list A first node is a atom variable a.hence flag is equal to 1.
The second atom of list A is sub list-((b,c). the second node will be down pointer pointing to sub list,
2)In Sub list both atom are variables(data).Hence Flag is equal to 0.

So,now from the above discussion I think that all of you are cleared with what a generalized link list looks like and how we store the data in it.
In further posts i  will give the hole idea for family tree using Generalized link list...
If anyone having doubts in the concepts dicusussed in post can comment below and if you like our posts,dont forget to share it...
        Thank you...

Structures in c++

As we are going to implement link list in our project, let us understand some basic concept
of structures in c++.
We often come around situations where we need to store a group of data whether of similar data types or non-similar data types.  Arrays in C++ which are used to store set of data of similar data types at contiguous memory locations.
                       Unlike Arrays, Structures in C++ are user defined data types which are used to store group of items of non-similar data types. A structure creates a data type that can be used to group items of possibly different types into a single type.                                            


 How to create a structure?
The ‘struct’ keyword is used to create a structure. The general syntax to create a structure is as shown below:
struct structureName
{ member1;
  member2;
  member3;
   .
   .
   .
   .
   .
   memberN;
};
Structures in C++ can contain two types of members:
  • Data Member: These members are normal C++ variables. We can create a structure with variables of different data types in C++.
  • Member Functions: These members are normal C++ functions. Along with variables, we can also include functions inside a structure declaration.
How to declare structure variables?
A structure variable can either be declared with structure declaration or as a separate declaration like basic types.

struct Point 
int x, y; 
} p1; // The variable p1 is declared with 'Point' 


// A variable declaration like basic data types 
struct Point 
int x, y; 
}; 

int main() 
struct Point p1; 
}

How to initialize structure members?

Structure members can be initialized using curly braces ‘{}’.

 For example,

struct Point 

int x, y; 
}; 

int main() 
struct Point p1 = {0, 1}; 
};


How to access structure elements?
Structure members are accessed using dot (.) operator.

#include <iostream> 
using namespace std; 

struct Point { 
int x, y; 
}; 

int main() 
struct Point p1 = { 0, 1 }; 
p1.x = 20; 
cout << "x = " << p1.x << ", y = " << p1.y; 

return 0; 
}

What is a structure pointer?
Like primitive types, we can have pointer to a structure. If we have a pointer to structure, members are accessed using arrow ( -> ) operator instead of the dot (.) operator.
#include <iostream> 
using namespace std; 

struct Point { 
int x, y; 
}; 

int main() 
struct Point p1 = { 1, 2 }; 
cout << p2->x << " " << p2->y; 
return 0; 
}

INTRODUCTION


Contributors:

1)Akshay Bharati
2) Dayanand Haral
3)aniket kapale
4)Atharv joshi


 In this project, you will learn the concepts of Datastructure and OOPs in c++ to write a code for making a family tree using generalized link list .The goal of this project is to get you comfortable with datastructure in C++. You've been using oops, but in this project you'll write more of them at one time than you have before.


          Before we start, we want to spend just a quick second talking about how I think about oops concepts, because I think it's a useful picture to have in your head. It helped me a lot.


why generlised linked list?

Generalized linked lists are used because although the efficiency of polynomial operations using linked list is good but still, the disadvantage is that the linked list is unable to use multiple variable polynomial equation efficiently. 
It helps us to represent multi-variable polynomial along with the list of elements.
generlised linked list contain structure or element with everyone containing   it's own pointer .
it's generlised if list can have deletion ,insertion and similar insertion effectively into it.


 typical sturucture of generlised lnk list in is as follow

typedef struct node
{
 char c;
 int index ;
 struct node *next ,*down;
}GLL;

 above is the basic structure of generlised linked list ,so by which we can create whole GLL.

FAMILY TREE



                       FAMILY TREE

           
•A family tree is a chart that shows all the people in a family over many generations and their relationship to one another.

•Typically, a generation is organized into a single level so it's easy to see at a glance which ancestors preceded which generation because they are physically above them on the tree.
Why family tree is important?
  • It gives you a connection to your heritage.
  • It can help you trace genetics and family health concerns.
  • It is a good exercise for learning your family history in relation to historical events.
•A horizontal line between two boxes indicates a marriage. A bracket from a couple to a lower set of boxes indicates the children from that marriage. 


DOCUMENTATION

Course project Title:      Implementation of Family tree Using Generalized Link List Description:    In this project we have create...