0% found this document useful (0 votes)
72 views6 pages

Qualcomm

The document contains code snippets related to linked lists, stacks, queues, strings, and arrays. Specifically, it includes functions to find the middle element of a linked list, detect loops in a linked list, implement a stack using a single queue, find the shortest unique substring in a string, and solve sudoku by checking rows and columns for duplicate values.

Uploaded by

Deepika Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
72 views6 pages

Qualcomm

The document contains code snippets related to linked lists, stacks, queues, strings, and arrays. Specifically, it includes functions to find the middle element of a linked list, detect loops in a linked list, implement a stack using a single queue, find the shortest unique substring in a string, and solve sudoku by checking rows and columns for duplicate values.

Uploaded by

Deepika Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

//Printing a middle element of a linked list

//Detecting the loop in a linked list

#include <iostream>
#include <cmath>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

struct node{
int a;
struct node *next;
};

void middleElement(struct node *head){


node* slowptr = head;
node* fastptr = head;
while( fastptr != NULL && fastptr -> next != NULL){
slowptr = slowptr -> next;
fastptr = fastptr -> next -> next;
}
int middleelement = slowptr -> a;
}

bool detectLoop(struct node *head){


node* slowptr = head;
node* fastptr = head;
while( fastptr != NULL && fastptr -> next != NULL){
if(slowptr == fastptr) return true;
slowptr = slowptr -> next;
fastptr = fastptr -> next -> next;

}
return false;
}

int main() {

return 0;
}
//How do you implement a stack with a single queue

//queue - enqueue(int),int dequeue and int front(),int rear()


//queue q;
//stack - push(int),int pop(), int top()

// s. push 10,20,30,40 - enqueue


//s.pop 40 s.top 40 - dequeue

#include <iostream>
#include <cmath>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

void push(int x,queue q){


//
for(int i = 0; i< q.size(); i++){
q.enqueue(x);
}
for(int i = 0; i< q.size()-1; i++){
q.dequeue();
}

int pop(queue q){


if(q.size()<1) {
cout<< "no element to pop";
}
q.dequeue();

int main() {
int num1, num2;
int sum;
cin>>num1>>num2;

sum = add_numbers(num1,num2);
cout << "The sum is " << sum;

return 0;
}

//Length of the smallest substring occurring only once in a given string


// string s = abcd
// a ,b ,c, d - 1
//string s = aabb
//a , b
//aa , bb - 2
//string s = abaab
//ab,aa,ba - 2
//string s = aaaa
//

#include <iostream>
#include <cmath>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int findLenSS(string &s){

for(int i =0; i< s.size(); i++){


s.substr(i, s.size());
}
}

int main() {
string s = "abaab";
cout<<findLenSS(s);
return 0;
}

int* func(){
int a = 2;
int *p = &a;
return p;
}

void main(){
int *p = func();
cout<<*p;
}

// Online C++ compiler to run C++ program online

#include <iostream>

/*

a : 3 - 011

b : 5 - 101

a xor b = 110

(110) && (111) = 110

*/

int flippednum(int a, int b){

int setbits = 0;

int res = a^b; // 110

while(res){

int andoperation = res & 1; //110 --> 100

res >>= 1; // 100 -> 000

setbits = setbits+ andoperation; //1 --> 2

return setbits;

int main() {
// Write C++ code here

int count = flippednum(10,15);

std::cout<< count;

return 0;

// Online C++ compiler to run C++ program online

#include <iostream>

void sudoku(){

for(int i = 0; i<4; i++){

if(mat[i][j]== 0 ){

for(int i = 0; i<4; i++){

for(int j = 0; j<4; j++){

if(mat[i][j])

int main() {
// Write C++ code here

std::cout << "Hello world!";

int mat[][];

for(int i = 0; i<3; i++){

for(int j = 0; j<3; j++){

std::cin<<mat[i][j]<<endl;

sudoku()

return 0;

You might also like