I have a structure
struct abc
{
int p;
int q;
}
and a file which gives the value of p and q and the operation that is to be done( insert,delete or modify) and then accordingly the values needs to be maintained in a sorted manner(sort acc to p).
The sequence is
1.Read the line from file
2.If insert, insert in a sorted manner<br>
If modify,delete; first remove the element and then sort<br>
3.Repeat step 1<br><br>
I already implemented this with a linked list but is there any other more time-efficient method than this?
I thought of an array(with memcpy-ing to ease the operations),set and vector but implementation wise it seems to be a bit difficult as all the operations has to done.
Would be helpful if i could get an algorithm or snapshot of the code
You shouldn't need to implement many operations.
Define your ordering relation:
Read the data:
Sort the data:
Insert while maintaining the order