do you know how to create simple linked list?
cos if u don't it will take a time until you learn this corectly...(as it did take mine :/ )
you can create it with template or without:
if without template than create an base class which will hold 2 pointers.
for example:
1 2 3 4 5 6 7 8
class first {
first *next, *previous;
protected:
getNext();
getPrevious ();
setNext ();
setPrevoius ();
};
now each class which you would like insert into list shall inherit "first class"
1 2 3 4 5 6 7
class Student : public first
{
int age;
char* name;
int grade;
// so on...
};
you shall create list class too...
which will manipulate with object's trought "first class"
each object will point to next and previous object using next and prevoius pointer
it will have functions insert () , remove () etc and function to save objects into file
this takes litle more code than this however here is declaration:
1 2 3 4 5 6 7 8 9
class list {
first *head, *end;
public:
insert ();
remove ();
saveToFile (first& );
addFromFile (first&);
//etc...
};
Can I create a linked list Class of binary file and save it?
Do you want to create a linked list that contains files (std::fstream objects) or build a list from the information stored in some file? Also, where are you going to save it? You can't save fstreams into any file and saving what you just read doesn't make sense.
and it is supported by the binary way of progrrming?
There is no such thing as a binary way of programming. What did you mean?
I somehow have a feeling you might be talking about binary trees..
I am not sure, but I think what he is trying to do is serialize a linked list to a file. To that, the answer is, you can't do it the same way you can an array. Due to the nature of linked lists, the only way to save them to a file is to save the information of each node to a file individually. If you want to save the node as a binary file, you can do something like:
A word of caution: This code assumes little endian on the part of the cpu. Don't use it if you intend your code to be portable across architectures. I leave it as an exercise to the reader to figure out how to get the data back out of the file and into a linked list.
PS. Every time I write code like this, someone always yells at me for something. So please take it easy this time. Also, I didn't really check the code, so there might be a few typos in it but the general idea is there.
look , I know how to pass over a list and find but now that i"m working on a binary file, it change somthing ???
I mean is it the same as I do that at a regular way ?
cause now I saved 4 example my list to a binary file and now my list is at a binary file and now I need to load that list and serch on it some data ... how I do that ?