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

Pointers, write short notes about void pointers

write short notes about void pointers

Program to create a class and store student information, Develop a Student ...

Develop a Student class that has the following header file: #ifndef STUDENT_H #define STUDENT_H #include #include #include using namespace std; class Stu

Dynamic memory management, C and C++ require explicit dynamic memory manage...

C and C++ require explicit dynamic memory management, using new and delete or malloc() and free(). It is helpful to understand where variables exist (usually the stack or the he

Define some features of register storage class in c program, Define some fe...

Define some features of register storage class in c program? The feature of variable defined to be of register type all as follows: Storage - CPU registers Default initia

Programing project, Hello, Do you have any idea for programming project to...

Hello, Do you have any idea for programming project to simulate a network attack (threat) mechanism or a defense mechanism. Can I get some suggestions for this. Please include th

PEBBLE MERCHANT, There is a pebble merchant. He sells the pebbles, that are...

There is a pebble merchant. He sells the pebbles, that are used for shining the floor. His main duty is to take the length of the room’s sides. But he sometimes mistakes doing that

C program to define power of a function, C program to define power of a fun...

C program to define power of a function: Write a program to use power of a function. void main() { int x,y,po=1,i,j; clrscr();   printf("Give x,y\n"); sca

Write a program that illustrate union declaration, Write a Program that ill...

Write a Program that illustrate union declaration? A C program encloses the following union declaration: union id { char color[12]; int size; } shirt, blouse; At this

Program, Define a class polynomial with three private data members a, b and...

Define a class polynomial with three private data members a, b and c of type double to represent the coefficient of two degree polynomial(ax^2+bx+c). Include a constructor in a pol

Memory management by c program, Memory management by c program: Write ...

Memory management by c program: Write a program to memory management in c program unsigned max( unsigned, unsigned );   int BaseMemBlocks::allocBlock( size_t sz )

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