Oops Projectts
Oops Projectts
Semester 3rd(Mor-B)
Class BS(SE)
Subject: Data Structure and Algorithms (CSI-401)
Submitted By: Muhammad salman Razzaq(4532)
Syed Saleeh Shah (4521)
Muhammad Umar Bashart (4539)
Ahmad Mujtaba (4535)
Submitted To: Dr.AWAIS
Question No. 1:
1…..
a. The Node must contain the following information in the DATA/INFO portion
i. Student Name
ii. Student Father Name
iii. Student Roll number
iv. Student Semester
v. Student CGPA
vi. Student GPA
vii. Student CNIC
……………………………………………………………………………………………………………………………………………
(a) …….
struct node
{
char name[5],father[5];
char semester[8];
int rollNo,CNIC;
float GPA,CGPA;
char section;
node *next;
}*head,*lastptr;
//(b) The user may search the List with any of the above mentioned
information and display the information of that node.
void search() //searches record of student//
{
node *prev=NULL;
node *current=NULL;
int CNIC;
cout<<"Enter CNIC to search:"<<endl;
cin>>CNIC;
prev=head;
current=head;
while(current->CNIC!=CNIC)
{
prev=current;
current=current->next;
}
cout<<"\nname: ";
puts(current->name);
cout<<"\nFather:";
puts(current->father);
cout<<"\nRoll_no:";
cout<<current->rollNo;
cout<<"\nSemester:";
puts(current->semester);
cout<<"\nSection:";
cout<<current->section;
cout<<"\nGPA:";
cout<<current->GPA;
cout<<"\nCGPA:";
cout<<current->CGPA;
getch();
//(c) The user can insert a new node with data at the end of the List
p->next=NULL;
if(check)
{
head = p;
lastptr = p;
check = false;
}
else
{
lastptr->next=p;
lastptr=p;
}
cout<<endl<<"Recored Entered";
getch();
}
Question NO: 2
as in the singly linked list, th doubly linked list also has a head and tail. The
previous pointer of the head is set to NULL as this is the first node. The next
pointer of the tail node is set to NULL as this is the last node
.
/*
* Insertion of element at a particular position
*/
void double_llist::add_after(int value, int pos)
{
if (start == NULL)
{
cout<<"First Create the list."<<endl;
return;
}
struct node *tmp, *q;
int i;
q = start;
for (i = 0;i < pos - 1;i++)
{
q = q->next;
if (q == NULL)
{
cout<<"There are less than ";
cout<<pos<<" elements."<<endl;
return;
}
}
tmp = new(struct node);
tmp->info = value;
if (q->next == NULL)
{
q->next = tmp;
tmp->next = NULL;
tmp->prev = q;
}
else
{
tmp->next = q->next;
tmp->next->prev = tmp;
q->next = tmp;
tmp->prev = q;
}
cout<<"Element Inserted"<<endl;
}
//(c) A node can be deleted……
* Deletion of element from the list
*/
void double_llist::delete_element(int value)
{
struct node *tmp, *q;
/first element deletion/
if (start->info == value)
{
tmp = start;
start = start->next;
start->prev = NULL;
cout<<"Element Deleted"<<endl;
free(tmp);
return;
}
q = start;
while (q->next->next != NULL)
{
/Element deleted in between/
if (q->next->info == value)
{
tmp = q->next;
q->next = tmp->next;
tmp->next->prev = q;
cout<<"Element Deleted"<<endl;
free(tmp);
return;
}
q = q->next;
}
/last element deleted/
if (q->next->info == value)
{
tmp = q->next;
free(tmp);
q->next = NULL;
cout<<"Element Deleted"<<endl;
return;
}
cout<<"Element "<<value<<" not found"<<endl;
}
/*
* Number of elements in Doubly Link List
*/
void double_llist::count()
{
struct node *q = start;
int cnt = 0;
while (q != NULL)
{
q = q->next;
cnt++;
}
cout<<"Number of elements are: "<<cnt<<endl;
}
/*
//(e) USIN LINKED LIST FOR IMPLEMENTING…..
class Node
{
public:
string c;
string a;
int data;
int key;
Node* next;
Node* customer;
};
head->next = newNode("2.Kelly\n");
head->next->next = newNode("3.Nelson\n");
head->next->next->next = newNode("4.Hall\n");
printList(head);
cout<<"Respective Query Numbers : BOND = 1" <<" KELLY = 2, NELSON = 3, HALL = 4 "<<endl;
push(&head, 1);
push(&head, 2);
push(&head, 3);
push(&head, 4);
else if (x==3)
{
cout<<"Broker Name: Neslson";
start->customer= new_Node("1.Teller 2.Jones 3.Adams 4.Rogers\n");
printf(start);
}
else
{
cout<<"Broker Name: Hall \n NO CUSTOMERS!";
} // end if
} //end main