Professional Documents
Culture Documents
printf("\n");
return 0;
}
4
}
printf("\n");
return 0;
}
7
int arr[size];
printf("Enter elements of the array:\n");
for (int i = 0; i < size; i++) {
scanf("%d", &arr[i]);
}
13
insertElement(matrix, 1, 2, 6);
insertElement(matrix, 2, 0, 7);
insertElement(matrix, 2, 1, 8);
insertElement(matrix, 2, 2, 9);
displayMatrix(matrix);
return 0;
}
16
}
// print the result
printf("The sum of the two matrices is: \n");
for (i = 0; i < m; i++) {
for (j = 0; j < n; j++) {
printf("%d ", c[i][j]);
}
printf("\n");
}
return 0;
}
18
}
20
sum=0;
for(k=0; k<3; k++)
sum = sum + mat1[i][k] * mat2[k][j];
mat3[i][j] = sum;
}
}
printf("\nMultiplication result of the two given Matrix is: \n");
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
printf("%d\t", mat3[i][j]);
printf("\n");
}
getch();
return 0;
}
22
}
}
void push(int val) {
if (isFull()) {
cout << "Stack Overflow" << endl;
} else {
top++;
arr[top] = val;
}
}
void pop() {
if (isEmpty()) {
cout << "Stack Underflow" << endl;
} else {
top--;
}
}
void traverse() {
if (isEmpty()) {
cout << "Stack is Empty" << endl;
} else {
cout << "Elements in the stack are:" << endl;
for (int i = top; i >= 0; i--) {
cout << arr[i] << " ";
}
26
}
}
void traverse(Node* head) {
Node* temp = head;
while (temp != nullptr) {
cout << temp->data << " ";
temp = temp->next;
}
cout << endl;
}
int main() {
Node* head = nullptr;
insertNode(head, 1);
insertNode(head, 2);
insertNode(head, 3);
insertNode(head, 4);
traverse(head);
return 0;
}
29
int main() {
Node* head = nullptr;
head = insertBeginning(head, 5);
head = insertBeginning(head, 10);
std::cout << "Linked List: ";
printList(head);
return 0;
}
31
while(temp->next != NULL)
temp = temp->next;
temp->next = newNode;
}
}
//display the content of the list
void PrintList() {
Node* temp = head;
if(temp != NULL) {
cout<<"The list contains: ";
while(temp != NULL) {
cout<<temp->data<<" ";
temp = temp->next;
}
cout<<endl;
} else {
cout<<"The list is empty.\n";
}
}
};
int main() {
LinkedList MyList;
//Add three elements at the end of the list.
MyList.push_back(10);
MyList.push_back(20);
33
MyList.push_back(30);
MyList.PrintList();
return 0;
}
34
void push ()
{
int num;
if (s.top == (MAXSIZE - 1))
{
printf ("Stack is Full\n");
return;
}
else
{
printf ("Enter the element to be pushed\n");
scanf ("%d", &num);
s.top = s.top + 1;
s.stk[s.top] = num;
}
return;
}
void display ()
{
int i;
if (s.top == -1)
{
printf ("Stack is empty\n");
return;
36
}
else
{
printf ("\n The status of the stack is \n");
for (i = s.top; i >= 0; i--)
{
printf ("%d\n", s.stk[i]);
}
}
printf ("\n");
}
37
display();
}
void push ()
{
int num;
if (s.top == (MAXSIZE - 1))
{
printf ("Stack is Full\n");
return;
}
else
{
printf ("Enter the element to push\n");
scanf ("%d", &num);
s.top = s.top + 1;
s.stk[s.top] = num;
}
return;
}
int pop ()
{
int num;
if (s.top == - 1)
{
printf ("Stack is Empty\n");
39
return (s.top);
}
else
{
num = s.stk[s.top];
printf ("poped element is = %dn", s.stk[s.top]);
s.top = s.top - 1;
}
return(num);
}
void display ()
{
int i;
if (s.top == -1)
{
printf ("Stack is empty\n");
return;
}
else
{
printf ("\n Current stack is \n");
for (i = s.top; i >= 0; i--)
{
printf ("%d\n", s.stk[i]);
}
40
} printf ("\n");
}
41
}
void dequeue() {
if (front == -1 || front > rear) {
cout << "Queue is empty" << endl;
} else {
cout << "Dequeued element: " << arr[front] << endl;
front++;
}
}
void traverse() {
if (front == -1) {
cout << "Queue is empty" << endl;
} else {
cout << "Queue elements: ";
for (int i = front; i <= rear; i++) {
cout << arr[i] << " ";
}
cout << endl;
}
}
};
int main() {
Queue q;
43
q.enqueue(10);
q.enqueue(20);
q.enqueue(30);
q.traverse();
q.dequeue();
q.traverse();
return 0;
}
44
return false;
}
void enqueue(int value) {
if (isFull()) {
cout << "Queue is full. Cannot insert element." << endl;
} else {
if (isEmpty()) {
front = 0;
}
rear++;
arr[rear] = value;
cout << value << " inserted into queue." << endl;
}
}
void display() {
if (isEmpty()) {
cout << "Queue is empty." << endl;
} else {
cout << "Queue elements: ";
for (int i = front; i <= rear; i++) {
cout << arr[i] << " ";
}
cout << endl;
}
}
46
};
int main() {
Queue q;
q.enqueue(10);
q.enqueue(20);
q.enqueue(30);
q.enqueue(40);
q.display();
return 0;
}
47
int element = 3;
removeElement(q, element);
while (!q.empty()) {
cout << q.front() << " ";
q.pop();
}
return 0;
}
49
}
}
printf("Sorted list in ascending order:\n");
for (c = 0; c < n; c++)
printf("%d\n", array[c]);
return 0;
}
51
return 0;
}
53
last = middle - 1;
middle = (first + last)/2;
}
if (first > last)
printf("Not found! %d isn't present in the list.\n", search);
return 0;
}