// Struct for linked list
#include
struct NODE {
NODE *pNxt;
NODE *pPev;
int iStudID;
char sStud[20];
};
NODE *pHead, *pTail;
The linked list program has five important functions consist of
" Attaching node at the end of the list
" Adding new node to the list
" Insert a new node to the list
" Delete the entire list
" Display contain all the list
===========================================================
// Appends a node to the end of the list
void AttachNode(NODE *pNode)
{
if (pHead == NULL) {
pHead = pNode;
pNode->pPrev = NULL;
}
else {
pTail->pNext = pNode;
pNode->pPrev = pTail;
}
pTail = pNode;
pNode->pNext = NULL;
}
// Inserts a node into the list after pAfter
void InsertNode(NODE *pNode, NODE *pAfter)
{
// your code here
}
// Removes the specified node from the list
void DelNode(NODE *pNode)
{
// your code here
}
// Deletes the entire list
void DelAllNodes()
{
while (pHead != NULL)
DeleteNode(pHead);
}
// Display the entire list
void DisplayAll()
{
// your code here
}
// main function
void main()
{
NODE *pNode;
// Add items to linked list
for (int i = 0; i <= 10; i++) {
pNode = new NODE;
pNode->iStudID = i;
// add code of student name here
AppendNode(pNode);
}
// Display each item in list
DisplayAll();
// Delete each item
DeleteAllNodes();
}
===========================================================
a. Write the code that will accept student name in the main function.
b. Based on the above struct, create three different functions that :
i. displaying all the list contents
ii. inserting a new node
iii. deleting a node
c. Apply multiple files concept in this program so that the program have struct.h, struct.c and main.c files.
d. Modify AttachNode function so that the node is inserted at the first node of the list.
e. Create Makefile base on the above program.
Read More...
[Source: Code Forums - Posted by Kishore Vengala]
No comments:
Post a Comment