linkedlist_implentation_usingarray.cpp File Reference

Linked list implementation using Arrays. More...

`#include <iostream>`
Include dependency graph for linkedlist_implentation_usingarray.cpp:

## Classes

class | Node

## Functions

void | initialise_list ()
int | getnode ()
void | freeNode (int nodeToBeDeleted)
void | insertAtTheBeginning (int data)
void | insertAtTheEnd (int data)
void | display ()
int | main ()

## Variables

Node | AvailArray [100]
| array that will act as nodes of a linked list.
int | head = -1
int | avail = 0

## Detailed Description

Linked list implementation using Arrays.

The difference between the pointer implementation of linked list and array implementation of linked list:

1. The NULL is represented by -1;
2. Limited size. (in the following case it is 100 nodes at max). But we can reuse the nodes that are to be deleted by again linking it bacj to the list.

## Function Documentation

## freeNode()

void freeNode | ( | int | nodeToBeDeleted | ) |

This function when called will delete the node with the index presented as an argument, and will put back that node into the array.

{
AvailArray[nodeToBeDeleted].next = avail;
avail = nodeToBeDeleted;
}
AvailArray
Node AvailArray[100]
array that will act as nodes of a linked list.
Definition: linkedlist_implentation_usingarray.cpp:19

## getnode()

int getnode | ( |  | ) |

This will return the index of the first free node present in the avail list

{
int NodeIndexToBeReturned = avail;
avail = AvailArray[avail].next;
return NodeIndexToBeReturned;
}

## insertAtTheBeginning()

void insertAtTheBeginning | ( | int | data | ) |

The function will insert the given data into the front of the linked list.

{
int newNode = getnode();
AvailArray[newNode].data = data;
AvailArray[newNode].next = head;
head = newNode;
}
data
int data[MAX]
test data
Definition: hash_search.cpp:24
getnode
int getnode()
Definition: linkedlist_implentation_usingarray.cpp:32
Here is the call graph for this function:

## main()

int main | ( | void |  | ) |

Main function

{
initialise_list();
int x, y, z;
for (;;) {
std::cout << "1. Insert At The Beginning" << std::endl;
std::cout << "2. Insert At The End" << std::endl;
std::cout << "3. Display" << std::endl;
std::cout << "4.Exit" << std::endl;
std::cout << "Enter Your choice" << std::endl;
std::cin >> z;
switch (z) {
case 1:
std::cout << "Enter the number you want to enter" << std::endl;
std::cin >> x;
insertAtTheBeginning(x);
break;
case 2:
std::cout << "Enter the number you want to enter" << std::endl;
std::cin >> y;
insertAtTheEnd(y);
break;
case 3:
std::cout
<< "The linked list contains the following element in order"
<< std::endl;
display();
break;
case 4:
return 0;
default:
std::cout << "The entered choice is not correct" << std::endl;
}
}
return 0;
}
std::cin
std::cout
std::endl
T endl(T... args)
insertAtTheBeginning
void insertAtTheBeginning(int data)
Definition: linkedlist_implentation_usingarray.cpp:50