Freecode - Thông tin công nghệ hàng đầu Việt nam
  • Home
  • Công nghệ AI
  • Mobile
  • Phần mềm
No Result
View All Result
  • Home
  • Công nghệ AI
  • Mobile
  • Phần mềm
No Result
View All Result
Freecode - Thông tin công nghệ hàng đầu Việt nam
No Result
View All Result
Home Mobile

Reverse a string or linked list using stack.

admin by admin
April 20, 2020
in Mobile
24
Reverse a string or linked list using stack.
0
SHARES
0
VIEWS
Share on FacebookShare on Twitter



See complete series on data structures here:

In this lesson, we have described how we can reverse a string or linked list using stack. Reversal is a simple application of stack.

To know about implicit stack, see this video:

Reversal of linked list using recursion:

For practice problems and more, visit:

Like us on Facebook:

Follow us on twitter:

Nguồn: https://freecode.com.vn

Xem thêm bài viết khác: https://freecode.com.vn/mobile

Xem thêm Bài Viết:

  • Lenovo A7000 bypass gmail verification 100%
  • Siêu Phẩm Lenovo Thinkpad P50 Max Option Màn 4K
  • Lenovo Vibe P1: обзор смартфона
  • iPad Pro 11 iPadOs: Which Mouse is Best??? Lenovo Vs. Apple
  • Moto M, REVIEW en español
Tags: Youtube
Previous Post

Ứng dụng lấy SĐT khách hàng truy cập vào website bằng 3g,4g

Next Post

Teaser Quân Vương Bất Diệt: Lee Min Ho phi ngựa xuyên không gặp crush

admin

admin

Next Post
Teaser Quân Vương Bất Diệt: Lee Min Ho phi ngựa xuyên không gặp crush

Teaser Quân Vương Bất Diệt: Lee Min Ho phi ngựa xuyên không gặp crush

Comments 24

  1. Sam says:
    1 year ago

    You are just amazing! You are truly, honestly, clearly deserved to work at Google!

    Reply
  2. Raghul G says:
    1 year ago

    Much Easier C code:

    #include <stdio.h>

    #include <stdlib.h>

    #include <string.h>

    struct Node{

    int data;

    struct Node *link;

    };

    struct Node *head;

    void push(int x)

    {

    struct Node *nod=(struct Node*)malloc(sizeof(struct Node));

    nod->data=x;

    nod->link=head;

    head=nod;

    }

    char pop()

    {

    char n;

    struct Node *temp=head;

    if(head==NULL) return;

    n=temp->data;

    head=head->link;

    free(temp);

    return n;

    }

    int main()

    {

    head=NULL;

    char A[100000],n;

    printf("Enter the string : ");

    gets(A);

    for(int i=0;i<strlen(A);i++)

    {

    push(A[i]);

    }

    for(int i=0;i<strlen(A);i++)

    {

    A[i]=pop();

    }

    for(int i=0;i<strlen(A);i++)

    {

    printf("%c",A[i]);

    }

    }

    Reply
  3. N says:
    1 year ago

    How can I copy the stack’s elements to another new stack?

    Reply
  4. Shreya Pandoh says:
    1 year ago

    C code:
    #include<stdio.h>
    #include<stdlib.h>
    #include<string.h>

    struct Node{
    char data;
    struct Node *link;
    };

    struct Node *top = NULL;
    void Push(char c);
    void Pop();

    void Push(char c)
    {
    struct Node *temp = (struct Node*)malloc(sizeof(struct Node*));
    temp->data = c;
    temp->link = top;
    top = temp;
    printf("%c", temp->data);
    }

    void Pop()
    {
    struct Node *temp;
    if(top==NULL)
    {
    return;
    }
    temp = top;
    top = top->link;
    printf("%c", temp->data);
    }

    int main()
    {
    char *str = (char*)malloc(sizeof(char));
    printf("Enter String: ");
    scanf("%s", str);
    int m = strlen(str);
    for(int i=0; i<m; i++)
    {
    Push(str[i]);
    }
    printf("n");
    for (int i=0; i<m; i++)
    {
    Pop();
    }
    printf("n");
    }

    Reply
  5. Tridib Samanta says:
    1 year ago

    Reverse a linked list using stack in CPP source code link –

    https://github.com/tridibsamanta/Data-Structures-and-Algorithms/blob/master/DS/Stack_LinkedListReverse.cpp

    Reply
  6. Li Mei says:
    1 year ago

    I know how 60 dislike happened….after I watch all this episodes I just feel that’s awesome!but I click dislike by mistake and I didn’t notice it!Right now I correct that mistake and I want to say thank you for offer such amazing video!!!

    Reply
  7. Dheerendra Arc says:
    1 year ago

    C Implementation

    #include<stdlib.h>
    #include<stdio.h>
    #define MAX_SIZE 10 //Maximum Size for Array.
    int top = -1;

    char str[MAX_SIZE], reverseStr[MAX_SIZE]; // Global Array Name “Str” and "reverseStr"

    // Define Push Operation for Stack.
    void push(char x){
    if(top == MAX_SIZE){
    printf("Stack Overflown");
    }
    reverseStr[++top] = x;
    }
    // Define Pop Operation for Stack.
    void pop(){
    if(top == -1){
    printf("Stack underflown”);
    }
    printf("%c", reverseStr[top]);
    –top;
    }

    int main(){
    int i = 0;
    scanf("%s", str);
    for(i=0;str[i]!='';i++){
    push(str[i]);
    }
    for(i=0;str[i]!='';i++){
    pop();
    }
    printf("n");
    return 0;
    }

    Reply
  8. suyash gupta says:
    1 year ago

    so grateful that this person made such a nice library of SUPER HELPFUL content which continues to help so many even after he's no longer here.

    Reply
  9. Rahul Arora says:
    1 year ago

    your channel name is school and you are explaining things so complexly, not a good teache .

    Reply
  10. hashtag popoy says:
    1 year ago

    why does it not read if i put a space between the words??

    Reply
  11. DEBANJAN PANIGRAHI says:
    1 year ago

    #include<stdio.h>

    #include<stdlib.h>

    struct node

    {

    char c;

    struct node *link;

    };

    struct node *head=NULL;

    void push()

    {

    struct node* temp;

    temp=(struct node*)(malloc(sizeof(struct node)));

    printf("enter a character : ");

    scanf("%c",&temp->c);

    fflush(stdin);

    temp->link=NULL;

    if(head==NULL)

    {

    head=temp;

    }

    else

    {

    temp->link=head;

    head=temp;

    }

    }

    void show()

    {

    struct node *p;

    p=head;

    while(p!=NULL)

    {

    printf("%c",p->c);

    p=p->link;

    }

    }

    int main()

    {

    push();

    push();

    push();

    push();

    push();

    show();

    }
    we dont need to perform pop operation to reverse a strig . the above code works fine.

    Reply
  12. Ryvr says:
    1 year ago

    In C
    #include <stdio.h>  

    #include <string.h>  

      

    #define max 100  

    int top,stack[max];  

      

    void push(char x){  

      

          // Push(Inserting Element in stack) operation  

          if(top == max-1){  

              printf("stack overflow");  

          }  else {  

              stack[++top]=x;  

          }  

      

    }  

      

    void pop(){  

        // Pop (Removing element from stack)  

          printf("%c",stack[top–]);  

    }  

      

      

    main()  

    {  

       char str[]="sri lanka";  

       int len = strlen(str);  

       int i;  

      

       for(i=0;i<len;i++)  

            push(str[i]);  

      

       for(i=0;i<len;i++)  

          pop();  

    }

    Reply
  13. Sukruthi Pattabi says:
    1 year ago

    Where is the source code ?

    Reply
  14. radhika ravi says:
    1 year ago

    thank you so much sir… thx for motivating us in DSA !! wish u good luck 🙂

    Reply
  15. Shalika Sinha says:
    1 year ago

    awesome teaching…cleared my concepts

    Reply
  16. stillFLiP says:
    1 year ago

    As we are using C++ I prefer using the appropriate functions instead of printf, fgets, strlen, etc.

    std::cout << "Enter a string: ";
    std::cin >> c;

    reverse(c, std::char_traits<char>::length(c));

    std::cout << "Ouput: " << c << std::endl;

    Reply
  17. vignesh war says:
    1 year ago

    Here is the complete code for 2nd program:

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

    struct Node
    {
    int value;
    Node *next;
    };

    void reverse(Node** head){

    Node* temp = *head;

    if(*head == NULL) return;

    stack<struct Node*> s;

    // push to stack
    while (temp!=NULL)
    {
    s.push(temp);
    temp = temp->next;

    }

    temp = s.top();
    *head = temp;
    s.pop();

    //reverse
    while (!s.empty())
    {

    temp->next = s.top();

    s.pop();
    temp = temp->next;
    }
    temp->next = NULL;

    }

    void push(Node **head, int value)
    {

    Node *temphead = *head;

    Node *temp = new Node();
    temp->value = value;
    temp->next = NULL;

    if (*head == NULL)
    {
    *head = temp;
    return;
    }

    while (temphead->next != NULL)
    {
    temphead = temphead->next;
    }
    temphead->next = temp;
    }

    // To print the linked list
    void print(Node *head)
    {
    Node *temp = head;

    while (temp != NULL)
    {
    cout << temp->value << "n";
    temp = temp->next;
    }
    }

    int main(){

    Node *head = NULL;

    push(&head, 1);
    push(&head, 2);
    push(&head, 3);

    print(head);

    reverse(&head);

    cout << "rev: "<< "n";
    print(head);

    return 0;
    }

    Reply
  18. Abdelrahman Hussein Ragab Swelam says:
    1 year ago

    the link to the practice problems is not working says "502 Bad Gateway"

    Reply
  19. Tushar Barman says:
    1 year ago

    RIP Harsha

    Reply
  20. Cybrary br says:
    1 year ago

    As always , like before watching 🙂

    Reply
  21. vaila ruthvik says:
    1 year ago

    http://blog.mycodeschool.com/ he's not dead!!! But these guys lost their teammate to a hit and run case back when I was in bangalore.

    Reply
  22. Emre Korkmaz says:
    1 year ago

    I wish you could be my data structure teacher 🙂 thanks for the videos , it helped me a lot 🙂

    Reply
  23. karyikey275 says:
    1 year ago

    c variant of this code

    #include<stdio.h>

    #include<conio.h>

    #include<string.h>

    #define max 20

    char a[max];

    int top = -1;

    void push(char z)

    {

    top++;

    a[top] = z;

    }

    void firstelenow()

    {

    printf("%c",a[top]);

    }

    void pop()

    {

    top = top-1;

    printf("%c",a[top]);

    }

    int main()

    {

    int n,i;

    char c[20];

    printf("nenter the stringn");

    gets(c);

    n = strlen(c);

    for(i= 0 ; i<n ; i++)

    {

    push(c[i]);

    }

    firstelenow();

    for(i= 0 ; i<n-1 ; i++)

    {

    pop();

    }

    return 0;

    }

    Reply
  24. Porus says:
    1 year ago

    the teacher is not between us any more …but his teaching would always be here for years….thanks for making all those videos ..may he is happy wherever he is…

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Tin Hot

10 mẹo sử dụng máy tính siêu hay chỉ dân xài lâu năm mới biết

10 mẹo sử dụng máy tính siêu hay chỉ dân xài lâu năm mới biết

February 21, 2021
Cách Tải Game Minecraft Trên Điện Thoại Iphone, Ipad Miễn Phí

Cách Tải Game Minecraft Trên Điện Thoại Iphone, Ipad Miễn Phí

June 24, 2020
FORTNITE Việt Nam #1: ĐỐI THỦ CỦA PUBG !!! KHÓ NHƯNG HAY VL !!!

FORTNITE Việt Nam #1: ĐỐI THỦ CỦA PUBG !!! KHÓ NHƯNG HAY VL !!!

June 24, 2020
Hướng dẫn cách đơn giản nhất để tải video và nhạc trên iPhone, Android

Hướng dẫn cách đơn giản nhất để tải video và nhạc trên iPhone, Android

June 23, 2020
Hướng dẫn cách download file và tài liệu trên Google driver mới nhất

Hướng dẫn cách download file và tài liệu trên Google driver mới nhất

June 23, 2020
Mẹo tải nhạc và video cho iPhone/iPad không cần máy tính

Mẹo tải nhạc và video cho iPhone/iPad không cần máy tính

June 23, 2020

Logo Freecode

Website freecode.com.vn cung cấp cho mọi người một cái nhìn khách quan nhất về thông tin công nghệ với nhiều tin tức nổi bật. Cùng xem những cập nhật mới nhất tại đây

  • Liên Hệ
  • Chính Sách Bảo Mật

© 2021 JNews - Premium WordPress news & magazine theme by Jegtheme.

No Result
View All Result
  • Home
  • Công nghệ AI
  • Mobile
  • Phần mềm

© 2021 JNews - Premium WordPress news & magazine theme by Jegtheme.