Tuesday, September 30, 2025

list in c#

 using System;

using System.Collections.Generic;
class Program {
    static void Main() {
        // Write your C# code here
        Console.WriteLine("Hello, World!");
        List<string>ShoppingList=new List<string>{
            "COFFEE","MILK","TEA"
        };
     
    Console.WriteLine(" enter string to search ");
      string search=Console.ReadLine();
    if(FindInList(search,ShoppingList,out int index)){
        Console.WriteLine($"Found {search} at {index}");
    }else{
        Console.WriteLine("not found");
    }
   
    }
     static bool FindInList(string item, List<string> list, out int index) {
        for (int i = 0; i < list.Count; i++) {
            if (string.Equals(list[i], item, StringComparison.OrdinalIgnoreCase)) {
                index = i;
                return true;
            }
        }
        index = -1;
        return false;
    }
}

Tuesday, September 23, 2025

circular queue

 #include <iostream>

 using namespace std;
 #define MAX 5
 class CircularQueue{
private:
int arr[MAX];
int front,rear;
public:
CircularQueue(){
    front =rear=-1;
}
bool isFull(){
    return(front==0 && rear==MAX-1)||(front==rear+1);
}
bool isEmpty(){
    return front==-1;
}
void enqueue(int value){
    if(isFull()){
        cout<<"queue is full "<<endl;
        return;
    }
    if(front==-1){
        front=rear=0;
    }
     else if (rear == MAX- 1 && front != 0) {
        rear = 0;
    }
    else{
        rear++;
    }
    arr[rear]=value;
}
void dequeue(){
   if(isEmpty()){
    cout<<" stack underflow "<<endl;
    return;
   }
   if(front==rear){
    front=rear=-1;
   }
   else if(front==MAX-1){
    front=0;
   }
   else{
    front++;
   }
}
void peek(){
    if(isEmpty()){
        cout<<" queue is empty "<<endl;
        return;
    }
    cout<<arr[front]<<endl;
}
void display(){
    if(rear>=front){
        for(int i=front;i<=rear;i++)
        cout<<arr[i]<<endl;
    }else{
       
   
     for (int i = 0; i <= rear; i++){
                cout << arr[i] << endl;
     }
    }
}
 };
 int main() {
 CircularQueue q;
  q.enqueue(10);
    q.enqueue(20);
    q.enqueue(30);
    q.enqueue(40);
    q.enqueue(50);

    q.display();

    q.dequeue();
    q.dequeue();
    q.display();
 return 0;
 }

Saturday, September 20, 2025

QUEUE

#include <iostream>
 using namespace std;
 #define MAX 100
 class QUEUE{
int front;
int rear;
int arr[MAX];
public:
QUEUE(){
    front=rear=-1;
}
bool isEmpty(){
    return (front==-1 && front==-1);
}
bool isFull(){
    return rear=MAX;
}
void enqueue(int value){
    if(isFull()){
        cout<<" queue overflow "<<endl;
        return;
    }
   if(isEmpty()){
    front=rear=0;
   }
   else{
    rear++;
   }
   cout<<arr[rear]<<endl;
}
void dequeue(){
    if(isEmpty()){
        cout<<" queue underflow "<<endl;
    }
    cout<<arr[front]<<" has been removed "<<endl;
    if(front==rear){
        front=rear=-1;
    }
    else{
        front++;
    }
}
int peek(){
    if(isEmpty()){
        cout<<"stack underflow "<<endl;
        return -1;
    }
return arr[front];
}
void display(){
    if(isEmpty()){
        cout<<" stack is empty "<<endl;
        return;
    }
    for(int i=front;i<=rear;i++){
        cout<<arr[i]<<endl;
    }
}
 };
 int main() {
 //Write your C++ code here
 cout << "Hello, World!" << endl;
 return 0;
 }

Friday, September 19, 2025

INFIX TO POSTFIX USING STACK

 #include <iostream>

#include <stack>
#include <cctype>
using namespace std;

int precedence(char op) {
    if (op == '+' || op == '-') return 1;
    if (op == '*' || op == '/') return 2;
    if (op == '^') return 3;
    return 0;
}

bool isRightAssociative(char op) {
    return op == '^';
}

bool isOperator(char op) {
    return (op == '+' || op == '-' || op == '*' || op == '/' || op == '^');
}

string infixToPostfix(string infix) {
    stack<char> st;
    string postfix = "";

    for (char &c : infix) {
        if (isalnum(c)) {
            postfix += c; // operand directly goes to output
        }
        else if (c == '(') {
            st.push(c);
        }
        else if (c == ')') {
            while (!st.empty() && st.top() != '(') {
                postfix += st.top();
                st.pop();
            }
            if (!st.empty()) st.pop(); // remove '('
        }
        else if (isOperator(c)) {
            while (!st.empty() && precedence(st.top()) > 0) {
                if ((!isRightAssociative(c) && precedence(c) <= precedence(st.top())) ||
                    (isRightAssociative(c) && precedence(c) < precedence(st.top()))) {
                    postfix += st.top();
                    st.pop();
                }
                else break;
            }
            st.push(c);
        }
    }

    // Pop remaining operators
    while (!st.empty()) {
        postfix += st.top();
        st.pop();
    }

    return postfix;
}

int main() {
    string infix;
    cout << "Enter Infix Expression: ";
    cin >> infix;

    string postfix = infixToPostfix(infix);
    cout << "Postfix Expression: " << postfix << endl;

    return 0;
}

Wednesday, September 3, 2025

MATCHING PARENTHESIS

 #include <iostream>

#include<stack>
 using namespace std;
 bool isMathcing(char opening,char closing){
    return (opening == '(' && closing == ')') ||
           (opening == '{' && closing == '}') ||
           (opening == '[' && closing == ']');
 }
 bool isBalanced(string str){
    stack<char>st;
    for(char ch:str){
        if(ch=='{'||ch=='('||ch=='['){
            st.push(ch);
        }
        else if (ch == ')' || ch == '}' || ch == ']') {
           
            if (st.empty() || !isMatchingPair(st.top(), ch)) {
                return false;
            }
            st.pop();
    }
 }
  return st.empty();
 }
 int main() {
 string expr;
 cout<<" enter an expression "<<endl;
 cin>>expr;
 if(isBalanced(expr)){
    cout<<" balanced parenthesis "<<endl;

 }else{
    cout<<" unbalanced parenthesis "<<endl;
 }
 return 0;
 }

Tuesday, September 2, 2025

STACK USING LINKED LIST

 #include <iostream>

 using namespace std;
 struct node{
    int data;
    node*next;
 };
 class Stack{
private:
node*top;
public:
Stack(){
    top=nullptr;
}
void push(int value){
    node*New=new node();
    New->data=value;
    New->next=top;
    top=New;

}
void pop(){
    if(isEmpty()){
        cout<<"stack underflow!cannot pop "<<endl;
        return;
    }
    node*temp=top;
    cout<<temp->data<<"has been popped "<<endl;
    top=top->next;
    delete temp;
}
void peek(){
    if(isEmpty()){
        cout<<"list is empty "<<endl;
        return;
    }
    cout<<top->data<<endl;
}
bool isEmpty(){
    return top==nullptr;
}
void display(){
    if(isEmpty()){
        cout<<"stack is empty "<<endl;
        return;
    }
    node*temp=top;
    while(temp!=nullptr){
cout<<temp->data<<endl;
temp=temp->next;
    }
}

 };
 int main() {
    Stack s;
    s.push(5);
    s.push(6);
    s.push(8);
    s.push(89);
    s.push(6123);
    s.display();
 return 0;
 }

list in c#

  using System ; using System . Collections . Generic ; class Program {     static void Main () {         // Write your C# code here  ...