Infix Conversions | Solution

แชร์
ฝัง
  • เผยแพร่เมื่อ 26 ม.ค. 2025

ความคิดเห็น • 47

  • @aishwaryadwani9365
    @aishwaryadwani9365 4 ปีที่แล้ว +17

    GOD Level teaching. Kudos to sir.

    • @Pepcoding
      @Pepcoding  4 ปีที่แล้ว +2

      Thankyou beta!
      I am glad you liked it. If you like our efforts, will you like to write a few words about us here (www.quora.com/How-do-I-start-learning-or-strengthen-my-knowledge-of-data-structures-and-algorithms )

  • @itsmechicpalak
    @itsmechicpalak 3 ปีที่แล้ว +6

    Sir truly you're God in explanation. Can't be more thankful!!!! 🙏🏻🙏🏻

  • @adarshsaraf9702
    @adarshsaraf9702 2 ปีที่แล้ว +1

    no one can teach better than u , exactly god level teaching

  • @vrindasharma4035
    @vrindasharma4035 2 ปีที่แล้ว +2

    Sir, you are so hardworking!!!!!!!!!! Just loved the way you try again n again for making things simpler!!!!!!!!!!

  • @stith_pragya
    @stith_pragya 8 หลายเดือนก่อน +1

    Thank You So Much for this wonderful video............🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻

  • @DataMetricsSolutions
    @DataMetricsSolutions 3 ปีที่แล้ว +1

    My Recommendation to everyone, as sir said, please watch the infix evaluation video, before watch this, you will love this video after that,

  • @ravishukla3987
    @ravishukla3987 3 ปีที่แล้ว +1

    no body explains this good
    🙏

  • @Python_DSA_Journey
    @Python_DSA_Journey 4 ปีที่แล้ว +4

    sir sach me aap khatarnak padhate hain kash thode aur pehle mile hote. to kya hi baat hoti :)

    • @Pepcoding
      @Pepcoding  4 ปีที่แล้ว +7

      I am glad bro. Aapke kaam aa rhi hain videos. Padhte rahie. Abhi sirf shuru hue hain. 800 videos to DS mei aur bnaenge firr Dev, ML, CORE jo bhi jaante hain sab daalenge.

    • @Python_DSA_Journey
      @Python_DSA_Journey 4 ปีที่แล้ว

      @@Pepcoding thank you sir...

  • @omprakash-dz2xh
    @omprakash-dz2xh 3 ปีที่แล้ว +1

    Instead of String v1 = oprnd.pop(); it should be
    String v1 = oprnd.isEmpty() ? "" : oprnd.pop();
    as it is failing for some test cases.
    Gr8 explanation btw :-)

  • @abhishekgupta3698
    @abhishekgupta3698 2 ปีที่แล้ว +1

    Sir aapne post aur pre naam ka stack banaya hai toh postfix naam ke stack mein push kaise kar rahe hai???

  • @DataMetricsSolutions
    @DataMetricsSolutions 3 ปีที่แล้ว +1

    Very good explanation sir, 7:45 if we accept only 4 operators +, -, * and / then after first if without else we can directly return 2 sir ?
    if(ch =='+' ||ch=='-'){
    return 1}
    return 2;
    is this correct sir?

    • @ashwinnema06
      @ashwinnema06 3 ปีที่แล้ว

      Yes its correct but don't write this in the interview because if you will write both conditions it will be more understandable to the interviewer

  • @kingshubham1993
    @kingshubham1993 3 ปีที่แล้ว +3

    Great explanation. Very detailed. Keep it up sir.

    • @Pepcoding
      @Pepcoding  3 ปีที่แล้ว

      Thankyou beta!
      I am glad you liked it. I hope that you are watching till the end and trying to understand what, how, and especially why of the problem.
      If you like our efforts, will you like to write a few words about us here (www.quora.com/What-are-the-good-websites-to-learn-data-structures-and-algorithms )

  • @shubhamgupta3396
    @shubhamgupta3396 3 ปีที่แล้ว +2

    Can we use Character.isLetterOrDigit(ch) function in If condition to check alphabet or digits?

    • @samiulkhan3744
      @samiulkhan3744 3 ปีที่แล้ว +1

      yes you can here's the code for your reference.
      class infixConversionStackPep {
      public static void main(String[] args) {
      Scanner sam = new Scanner(System.in);
      String str = sam.nextLine();
      Stack pre = new Stack();
      Stack post = new Stack();
      Stack optors = new Stack();
      for(int i =0;i0 && optors.peek()!='('){
      char op = optors.pop();
      String v2pre = pre.pop();
      String v1pre = pre.pop();
      String valpre = value(v1pre,v2pre,String.valueOf(op),"pre");
      pre.push(valpre);
      String v2post = post.pop();
      String v1post = post.pop();
      String valpost = value(v1post,v2post,String.valueOf(op),"post");
      post.push(valpost);
      }
      optors.pop();
      }else if(Character.isLetterOrDigit(ch)){
      pre.push(String.valueOf(ch));
      post.push(String.valueOf(ch));
      }else if(ch=='*'||ch=='+'||ch=='-'||ch=='/'){
      while (optors.size()>0 && optors.peek()!='(' && precedence(ch)0){
      char op = optors.pop();
      String v2pre = pre.pop();
      String v1pre = pre.pop();
      String valpre = value(v1pre,v2pre,String.valueOf(op),"pre");
      pre.push(valpre);
      String v2post = post.pop();
      String v1post = post.pop();
      String valpost = value(v1post,v2post,String.valueOf(op),"post");
      post.push(valpost);
      }
      System.out.println(pre.peek());
      System.out.println(post.peek());
      }
      public static int precedence(char optors){
      if(optors=='+'){
      return 1;
      }else if(optors=='-'){
      return 1;
      }else if(optors=='*'){
      return 2;
      }else {
      return 2;
      }
      }
      public static String value(String v1,String v2,String optor,String fun){
      if(fun=="pre"){
      return optor+v1+v2;
      }else {
      return v1+v2+optor;
      }
      }
      }

  • @chandanagarwal2827
    @chandanagarwal2827 4 ปีที่แล้ว

    on 20:02 line no. 34 if we don't check for ops.peek() != '(' then also the code will run fine because precedence will always return lower value for '(' and will never go beyond it.

    • @samstar9777
      @samstar9777 4 ปีที่แล้ว +1

      Uss line ki wajah se kuch error aa rha hai, run hi nahi ho rha. Keeps showing runtime error

  • @travelnlearn
    @travelnlearn 2 ปีที่แล้ว

    Awesome videos

  • @iffyaiyan8942
    @iffyaiyan8942 4 ปีที่แล้ว +2

    Though it took more time to get but it was best explanation

    • @Pepcoding
      @Pepcoding  4 ปีที่แล้ว +1

      No issues beta, lge rho aise he aur aage bdte rho😊

  • @ashwinnema06
    @ashwinnema06 3 ปีที่แล้ว

    Nice exaplanation sir. I daily solve questions from pepcoding resources. Its really helpful

    • @Pepcoding
      @Pepcoding  3 ปีที่แล้ว

      Thanks :) Hope you are also making the use of nados.pepcoding.com

  • @TabrezAlikhan7960
    @TabrezAlikhan7960 2 ปีที่แล้ว

    You are azming teaching in world

  • @AJITSINGH-ez1it
    @AJITSINGH-ez1it 3 ปีที่แล้ว

    i didn't applied logic of identifying abcd or number and all, instead i used else ..

  • @aritralahiri8321
    @aritralahiri8321 3 ปีที่แล้ว

    Great Intuitive Explanation

    • @Pepcoding
      @Pepcoding  3 ปีที่แล้ว +1

      Glad it was helpful! and f you like our efforts, please upvote the comments written by the students about Pepcoding here (www.quora.com/What-are-the-good-websites-to-learn-data-structures-and-algorithms )

  • @chandanagarwal2827
    @chandanagarwal2827 4 ปีที่แล้ว +1

    Guruji 200 din wali sprint start kar rha hu aaj se dekhte hai agle 1 sal me kya hota hai.

    • @Pepcoding
      @Pepcoding  4 ปีที่แล้ว +2

      bhai bhot mushkil hogi. jalna hoga. firr aisa hai ki jalne mei jo mza hai, wo parvane jaante hai! eeshwar aapko aur humei sahi rakhe.

    • @chandanagarwal2827
      @chandanagarwal2827 4 ปีที่แล้ว +1

      @@Pepcoding jalne ka to pta nahi guruji baki apni traf se to 100% effort dalunga, abhi to naukri hai nahi 1 sal ho gya engineering ko, or kuch nahi hua to pitaji ki dukan to hai hi, usi ke liye koi software bna lenge dhang ka sa

    • @virtualworld6311
      @virtualworld6311 3 ปีที่แล้ว

      ka progress ha bro ?

    • @boredpotato6366
      @boredpotato6366 3 ปีที่แล้ว

      Haan bhai progress and results batao

    • @chandanagarwal2827
      @chandanagarwal2827 3 ปีที่แล้ว +1

      @@boredpotato6366 Lag gayi bro naukri 200 din se phle hi

  • @SCRIPTSAG
    @SCRIPTSAG 4 ปีที่แล้ว

    Sir es code me () use kerne pe stack empty error as rha hai normal 2+3 se eroor nhi aa rhahai

    • @Pepcoding
      @Pepcoding  4 ปีที่แล้ว

      () ka kuch matlab nahi hua na. invalid / empty expression hai.

  • @rafath1403
    @rafath1403 4 ปีที่แล้ว

    sir I'm getting this runtime error Exception in thread "main" java.util.EmptyStackException
    at java.base/java.util.Stack.peek(Stack.java:102)
    at java.base/java.util.Stack.pop(Stack.java:84)
    at Main.main(Main.java:28)
    The code is exactly like that of yours but it keeps throwing this error

    • @Pepcoding
      @Pepcoding  4 ปีที่แล้ว +1

      Beta, I regret to inform you that, I won't be able to answer/solve the personal doubts of each and every student over here. For clearing your doubts, you can join our community on telegram - t.me/pepcoding.

    • @samiulkhan3744
      @samiulkhan3744 3 ปีที่แล้ว

      class infixConversionStackPep {
      public static void main(String[] args) {
      Scanner sam = new Scanner(System.in);
      String str = sam.nextLine();
      Stack pre = new Stack();
      Stack post = new Stack();
      Stack optors = new Stack();
      for(int i =0;i0 && optors.peek()!='('){
      char op = optors.pop();
      String v2pre = pre.pop();
      String v1pre = pre.pop();
      String valpre = value(v1pre,v2pre,String.valueOf(op),"pre");
      pre.push(valpre);
      String v2post = post.pop();
      String v1post = post.pop();
      String valpost = value(v1post,v2post,String.valueOf(op),"post");
      post.push(valpost);
      }
      optors.pop();
      }else if(Character.isLetterOrDigit(ch)){
      pre.push(String.valueOf(ch));
      post.push(String.valueOf(ch));
      }else if(ch=='*'||ch=='+'||ch=='-'||ch=='/'){
      while (optors.size()>0 && optors.peek()!='(' && precedence(ch)0){
      char op = optors.pop();
      String v2pre = pre.pop();
      String v1pre = pre.pop();
      String valpre = value(v1pre,v2pre,String.valueOf(op),"pre");
      pre.push(valpre);
      String v2post = post.pop();
      String v1post = post.pop();
      String valpost = value(v1post,v2post,String.valueOf(op),"post");
      post.push(valpost);
      }
      System.out.println(pre.peek());
      System.out.println(post.peek());
      }
      public static int precedence(char optors){
      if(optors=='+'){
      return 1;
      }else if(optors=='-'){
      return 1;
      }else if(optors=='*'){
      return 2;
      }else {
      return 2;
      }
      }
      public static String value(String v1,String v2,String optor,String fun){
      if(fun=="pre"){
      return optor+v1+v2;
      }else {
      return v1+v2+optor;
      }
      }
      }
      take a look it might help,and dont forget to pop the opening barces at line number 29

  • @jatinbhatoya8420
    @jatinbhatoya8420 3 ปีที่แล้ว

    sir isko tree wale tareeke se bhi krke dikha do

  • @jobanpreetsingh2370
    @jobanpreetsingh2370 2 ปีที่แล้ว

    It took me 2hrs to code by myself 😐😐

    • @Pepcoding
      @Pepcoding  2 ปีที่แล้ว

      Practice makes you perfect, keep working hard. For better experience and curated content sign up on nados.io, you can also post your queries on community tab of NADOS.