Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
Example of c program that contain 
1. traversing
2. Insertion
3. Deletion
4. searching
5.sorting


What I have tried:

I want to see how to use c code to perform this question in order to memorize it
Posted

Quote:
I want to see how to use c code to perform this question in order to memorize it
Then you need to use your class notes, and reference guides to help you write it. Sorry, but no one here is going to do your work for you.
 
Share this answer
 
The requested operations need a dynamic array, as data structure.
There are many tutorials available on the web on the very topic "dynamic array in C". Google is your friend.
 
Share this answer
 
The operations mentioned are usually implemented with a linked list.

The definition for a list element is usually this:
C
struct Node {
    int data;
    struct Node *next;
};

In the main program, you can then use it as follows:
C
int main() 
{
  struct Node *head = NULL;
 
  head = insertNode(head, 5); // Insert elements
  ...

  return 0;
}

The first function required would then be insertNode(), which inserts a new element into the list.

The prototype for this could look like this, for example:
C
struct Node* insertNode(struct Node *head, int value);

The optimal data structure depends on the specific requirements of the program. If frequent access to random elements is important or sorting operations are to be performed frequently, an array might be more suitable; linked lists offer good performance when inserting and deleting elements. A search tree could also be considered for a high-performance search. However, the implementation of a search tree is more complex than that of a linked list.

That should be enough for you to manage the rest yourself. If something does not work, specific questions would be necessary.
 
Share this answer
 
v3
Comments
Andre Oosthuizen 29-Nov-23 12:07pm    
+5, nice pointers given to OP.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900