Apr 30, 2013 at 6:36pm UTC
Hi i'm trying to read out the some code that i search in google. And i try to differentiate the code whether its using what kind of data structure.. Its using binary tree, queue, tree or vector or others?
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 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308
#include<iostream>
#include<time.h>
#include<math.h>
#include<iomanip>
using namespace std;
class studentrecord
{
public :
studentrecord();
char fname[10];
char lname[10];
int ID;
char programme[10];
int year_of_study;
studentrecord *nxt;
void register_student();
void display_all();
void displayStudentInformation();
void Swap();
void SearchStudent();
void DeleteStudent();
void ConditionalDisplay();
};
studentrecord::studentrecord()
{
}
studentrecord *start_ptr=NULL;
int khetho=0;
void studentrecord::register_student()
{
studentrecord *temp,*temp2;
temp=new studentrecord;
cout<<"enter the student fist name:" <<endl;
cin>>temp->fname;
cout<<"enter student last name:" <<endl;
cin>>temp->lname;
cout<<"enter student id:" <<endl;
cin>>temp->ID;
cout<<"Enter the Programme of the student:" <<endl;
cin>>temp->programme;
cout<<"Enter student's year:" <<endl;
cin>>temp->year_of_study;
temp->nxt=NULL;
if (start_ptr==NULL)
{
start_ptr=temp;
}
else
{
temp2=start_ptr;
while (temp2->nxt!=NULL)
{
temp2=temp2->nxt;
}
temp2->nxt=temp;
}
}
void studentrecord::display_all()
{
studentrecord *temp;
temp=start_ptr;
if (start_ptr==NULL)
{
cout<<"the record is empty" <<endl;
}
else
{
while (temp!=NULL)
{
cout<<"last name is:" <<temp->lname<<endl;
cout<<"ID:" <<temp->ID<<endl;
cout<<"first name is:" <<temp->fname<<endl;
cout<<"the programme is:" <<temp->programme<<endl;
cout<<endl;
cout<<endl;
temp=temp->nxt;
}
}
}
void studentrecord::Swap()
{ studentrecord *temp,*temp2,*temp3,*temp4;
temp= start_ptr;
cout<<endl;
int id,id1; //count;
cout<<"enter ID u want to swap " <<endl;
cin>>id;
cout<<"enter 2nd ID u want to swap " <<endl;
cin>>id1;
if (start_ptr == NULL)
{
cout << "The list is empty!" << endl;
}
while (temp!=NULL)
{
if (temp->ID=id1)
{
temp2=temp;
temp=temp->nxt;
}
}
while (temp3!=NULL)
{
if (temp3->ID=id1)
{
temp4=temp3;
temp3=temp3->nxt;
}
}
temp->nxt=temp4;
temp3->nxt=temp2;
temp->nxt=temp3->nxt;
temp3->nxt=temp->nxt;
//temp4->nxt=temp2->nxt;
//temp2->nxt=temp4->nxt;
//temp3->nxt=temp2;
// temp2->nxt=temp->nxt;
// delete temp;
cout<<endl;
// cout<<count;
}
void studentrecord:: SearchStudent()
{ studentrecord *temp;
temp= start_ptr;
cout<<endl;
int id,count=0;
cout<<"enter student ID u want to search for" ;
cin>>id;
if (start_ptr == NULL)
cout << "The list is empty!" << endl;
else
{
while (temp!=NULL )
{
if (temp->ID==id)
{
cout<<"ID :" <<temp->ID<<endl;
cout<<"First Name: " <<temp->fname<<endl;
cout<<"Last Name: " <<temp->lname<<endl;
cout<<"Programme: " <<temp->programme<<endl;
cout<<"Year of Study: " <<temp->year_of_study<<endl;
count++;
}
//temp->display_list();
temp = temp->nxt;
}
cout<<endl;
cout<<count;
}
}
void studentrecord:: DeleteStudent()
{ studentrecord *temp,*temp2;
temp= start_ptr;
cout<<endl;
int id, count;
cout<<"enter id u wana delete" ;
cin>>id;
if (start_ptr == NULL)
{
cout << "The list is empty!" << endl;
}
if (start_ptr->ID = id)
{
temp=start_ptr;
start_ptr=start_ptr->nxt;
delete temp;
}
else
{
while (temp->ID!=id)
{
temp2=temp;
cout<<temp->ID;
count++;
temp = temp->nxt;
}
temp2->nxt=temp->nxt;
delete temp;
cout<<endl;
cout<<count;
}
}
void studentrecord::ConditionalDisplay()
{ studentrecord *temp;
temp= start_ptr;
cout<<endl;
int count=0;
char lastname[20];
cout<<"Enter the Last Name to search: " ;
cin>>lastname;
if (temp == NULL)
cout << "The list is empty!" << endl;
else
{
while (temp!=NULL )
{
if (temp->lname==lastname)
{
cout<<endl;
cout<<temp->lname<<endl;
cout<<temp->fname<<endl;
cout<<temp->ID<<endl;
cout<<temp->ID<<endl;
cout<<temp->year_of_study<<endl;
temp=temp->nxt;
}
//temp->display_list();
temp = temp->nxt;
}
cout<<endl;
cout<<"There are " <<count<<"maches" ;
}
}
void studentrecord:: displayStudentInformation()
{ studentrecord *temp;
temp= start_ptr;
cout<<endl;
int id,count=0;
cout<<"enter id to get student information" ;
cin>>id;
if (temp == NULL)
cout << "The list is empty!" << endl;
else
{
while (temp!=NULL )
{
if (temp->ID==id)
{
cout<<temp->fname<<endl;
cout<<temp->lname<<endl;
cout<<temp->ID<<endl;
cout<<temp->year_of_study<<endl;
cout<<endl;
count++;
}
//temp->display_list();
temp = temp->nxt;
}
cout<<endl;
cout<<count;
}
}
void main()
{
//start_ptr = NULL;
studentrecord l;
do
{
cout << " ______________________________" <<endl;
cout << " Please select a choice : " << endl;
cout << " ______________________________" <<endl;
cout << " 0. Exit the program." << endl;
cout << " 1. register student." << endl;
cout << " 2. search student." << endl;
cout << " 3. Swap student postion." << endl;
cout << " 4. display student information." << endl;
cout << " 5. display all." << endl;
cout << " 6. conditional display." <<endl;
cout << " 7. delete." <<endl;
cout << " _______________________________" <<endl << "" ;
cin >> khetho;
switch (khetho)
{
case 1 : l.register_student();
cout<<" " ;system("pause" );
system("cls" );
break ;
case 2 : l.SearchStudent(); break ;
case 3 : l.Swap(); break ;
case 4 : l.displayStudentInformation(); break ;
case 5 : l.display_all();break ;
case 6 : l.ConditionalDisplay();break ;
case 7 : l.DeleteStudent();break ;
}
}
while (khetho != 0);
}
Last edited on Apr 30, 2013 at 6:42pm UTC
May 1, 2013 at 1:53pm UTC
i get the concept of the queue, tree,binary tree and vector.. but once it from the code i cannt see the concept.. as u said queue FIFO.. but in code, i cannt differenciate it.. and i still cannt get ur point
May 1, 2013 at 2:55pm UTC
Isn't this a Linked List ???
May 1, 2013 at 5:08pm UTC
i getting confuse with the question if asking to develop using binary tree or tree data structure? whats diff?
May 1, 2013 at 7:46pm UTC
All trees are trees, but only binary trees are binary trees. Binary == 2 == each node has at most two children. Binary tree is one special case of a tree.