Project: Subject: Data Structure Course Code: CS-204 Instructor: Ms. Fakhra Nazir
Project: Subject: Data Structure Course Code: CS-204 Instructor: Ms. Fakhra Nazir
Submitted by
Name: Qandeel Zulfiqar
Roll No: 19010819-074
Class: MSc-cs-(iii)
University of Gujrat
GT Road campus, Gujrat
Problem #01
Code:
#include<iostream>
using namespace std;
struct Node
{
string Name;
string F_Name;
int F_No;
int Marks;
Node* next;
Node* prev;
};
struct Node*head, *Last;
void STD(string nm,string fnm,int fno,int m)
{
if (head == NULL)
{
struct Node* newnode = new Node;
newnode->Name = nm;
newnode->F_Name = fnm;
newnode->F_No = fno;
newnode->Marks = m;
newnode->next = newnode->prev = newnode;
head = newnode;
return;
}
Last = head->prev;
newnode->next = head;
head->prev = newnode;
newnode->prev = Last;
Last->next = newnode;
}
void Add_STD()
{
Node* p;
p = new Node;
if (Check)
{
head = p;
Last = p;
Check = false;
}
else
{
Last->next = p;
Last = p;
}
cout << endl << "Student Added Successfully..!";
}
void Eligibility_STD(){
int Search_STD()
{
int count=0,flag=0,value;
int search;
cout<<"enter file no"<<endl;
cin>>search;
if(temp == NULL)
return -1;
else
{
while(temp->next != head)
{
count++;
if(temp->F_No == search)
{
flag = 1;
count--;
break;
}
temp = temp->next;
}
if(temp->F_No == search)
{
count++;
flag = 1;
}
if(flag == 1)
cout<<"\n"<<search <<" found at location "<< count;
else
cout<<"\n"<<search <<" not found ";
}
}
void Del_STD()
{
if (head == NULL)
return;
if (curr->next == head) {
cout<<"\nThere is no student with file no = "<< key;
return;
}
prev_1 = curr;
curr = curr->next;
}
if (curr == head) {
prev_1 = head->prev;
head = head->next;
prev_1->next = head;
head->prev = prev_1;
free(curr);
}
prev_1->next = head;
head->prev = prev_1;
free(curr);
}
else {
struct Node* temp;
temp = curr->next;
prev_1->next = temp;
temp->prev = prev_1;
free(curr);
}
}
int main()
{
cout<<endl;
int x;
do
{
cout << "1) Add New Student" << endl;
cout << "2) Search Student" << endl;
cout << "3) Eligible Student" << endl;
cout << "4) Delete Student" << endl;
cout << "0) Exit:" << endl;
cin >> x;
if (x == 1)
{
Add_STD();
}
else if (x == 2)
{
Search_STD();
}
else if (x == 3)
{
Eligibility_STD();
}
else if (x == 4)
{
Del_STD();
}
else
{
}
}
while (x != 0);
return 0;
}