-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlinked_list.cpp
More file actions
66 lines (52 loc) · 1.24 KB
/
Copy pathlinked_list.cpp
File metadata and controls
66 lines (52 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
//#include "protein.h"
#include "linked_list.h"
//this function insert a atom node, if there is no atom node create anew one
//if there already is a atom node, then insert a new atom node after this atom node
template <class Item>
void insert_an_node(node<Item>*& head_ptr,node<Item>*& previous_ptr,Item*& entry)
{
node<Item> *insert_ptr;
if(previous_ptr==NULL)
{
previous_ptr=new node<Item>;
previous_ptr->data=entry;
head_ptr=previous_ptr;
}
else
{
insert_ptr=new node<Item>;
insert_ptr->data=entry;
previous_ptr->next=insert_ptr;
previous_ptr=insert_ptr;
}
previous_ptr->next=NULL;
}
//this function print atom node linked list
template <class Item>
void display_node_list(node<Item> *start_ptr)
{
ofstream new_pdb("output_list.txt",ios::out);
if(start_ptr == NULL)
{cout<<"the list is empty ! "<<endl;}
else
{
while(start_ptr!=NULL)
{
new_pdb<<start_ptr->data;
start_ptr=start_ptr->next;
}
}
new_pdb.close();
}
template<class Item>
int linked_list_length(node<Item>*& head_ptr)
{
node<Item>* cursor_ptr;
int length;
length=0;
for(cursor_ptr=head_ptr;cursor_ptr!=NULL;cursor_ptr=cursor_ptr->next)
{
length=length+1;
}
return length;
}