Define the self-referential structures, C/C++ Programming

Assignment Help:

Define the Self-Referential Structures?

It is occasionally desirable to include within a structure one member that is a pointer to the parent structure type. Generally in terms this can be expressed as

struct tag
{
member 1;
member 2;
. . . . .
struct tag *name;
} ;

Where name refers to the name of a pointer variable therefore the structure of type tag will contain a member that points to another structure of type tag. Such structures are called as self-referential structures.

A C program contains the following structure declaration.

struct list_element
{
char item[40];
struct list_element *nextj
} ;

This is a structure of type list_element and the structure encloses two members a 40-element character array, called item, and a pointer to a structure of the same type (that is a pointer to a structure of type list_element), called next. Thus this is a self-referential structure. .

The Self-referential structures are extremely useful in applications that involve linked data structures, such as trees and lists. The fundamental idea of a linked data structure is that each component within the structure includes a pointer indicating where the next component is able to be found. Consequently the relative order of the components can simply be changed simply by altering the pointers. As well individual components can easily be deleted or added again by altering the pointers. As a result, a linked data structure isn't confined to some maximum number of components. Somewhat the data structure can expand or contract in size as required.

Figure shown below exemplify a linked list containing three components. Every component consists of two data items a string, and a pointer that references the next component within the list. Therefore the first component contains the string "red" the second contains "green" and the third contains "blue". The start of the list is indicated by a separate pointer, which is labeled "start". As well, the end of the list is indicated by a special pointer called as "NULL".

1623_Self-Referential Structures.png


Related Discussions:- Define the self-referential structures

How do one throw polymorphically?, How do one throw polymorphically?       ...

How do one throw polymorphically?               A: Sometimes people write code such as: class MyExceptionBase { }; class MyExceptionDerived : public MyExceptionBase { };

How do i develop a subscript operator for a matrix class?, Employ operator ...

Employ operator () instead of operator[]. While you have multiple subscripts, the cleanest way to do it is along with operator () instead of with operator[]. The reason is that

Stack, c++ program to to implement multiple stacks using single array

c++ program to to implement multiple stacks using single array

Applied scientific computing in c++, i have a project that is due this Wedn...

i have a project that is due this Wednesday and i was wondering if i can get help in doing it?

Develop an e commerce site, We need an E Commerce site likefifacointrader. ...

We need an E Commerce site likefifacointrader. you must have experience with that kind of work You have to show a sample of work like that site. Skills required are C Prog

Decode the Code, Smugglers are becoming very smart day by day. Now they hav...

Smugglers are becoming very smart day by day. Now they have developed a new technique of sending their messages from one smuggler to another. In their new technology, they are send

Execution of string length using pointer hopping, A: #include // Test to...

A: #include // Test to see if pointer hopping is worthwhile. // strlen implemented with usual indexing mechanism. int strlen1( const char str[ ] ) { int i; for( i =

Define statements to define the constants, the problem description. The ...

the problem description. The order of the C Program should be as follows: Variables and constants Use #define statements to define the constants. Use arr

How to write Bernoulli''s principle, compose a C program to solve the equat...

compose a C program to solve the equation z2=(p1/Pg)+(v1^2/2g)+z1 p1=100kpa,v1=2m/s z1=3m P=1000kg/m^3 define g=9.81

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd