Professional Documents
Culture Documents
Hubeali Assgn2
Hubeali Assgn2
SUBMITTED TO:
SIR RAZA
Hub-e-Ali
SP14-BET-0
Question 1
#include<conio.h>
#include<stdio.h>
struct node
int data;
node *next;
};
class lList
node *head,*tail;
public:
lList()
head = NULL;
tail = NULL;
temp->data = value;
temp->next = NULL;
if (head == NULL)
{
head = temp;
tail = temp;
temp = NULL;
} else
tail->next = temp;
tail = temp;
void display()
temp = head;
temp = temp->next;
temp->data = value;
temp->next = head;
head = temp;
{
node *pre = new node;
cur = head;
pre = cur;
temp->data = value;
pre->next = temp;
temp->next = cur;
temp->data = value;
temp->next = NULL;
if (head == NULL) {
head = temp;
tail = temp;
temp = NULL;
} else {
tail->next = temp;
tail = temp;
}
void deleteFirst()
temp = head;
head = head->next;
delete temp;
void deleteLast()
current = head;
previous = current;
current = current->next;
tail = previous;
previous->next = NULL;
delete current;
current = head;
{
previous = current;
current = current->next;
previous->next = current->next;
int ctr=1;
temp=head;
while(temp!=NULL)
if(value==temp->data)
ctr++;
break;
else
ctr++;
temp=temp->next;
};
main()
{
lList obj;
int search1,sagn;
obj.createNode(25);
obj.createNode(50);
obj.createNode(90);
obj.display();
cout<<endl<<endl<<"Please Enter:"<<endl;
cin>>search1;
obj.search(search1);
cout<<"Do you want to search again enter 0 for again or 1 for exit"<<endl;
switch(sagn){
case 0:{
obj.search(search1);
break;
case 1:{
//exit(0);
break;
getch();
Question 2
#include<stdio.h>
if (arr[mid] == x)
return mid;
if (arr[mid] < x)
std = mid + 1;
else
end = mid - 1;
return -1;
main()
int arr[5];
for(int i=0;i<5;i++)
cin>>arr[i];
}
int n = sizeof(arr)/ sizeof(arr[0]);
int x;
cin>>x;
if(result == -1)
else
getch();