تبلیغات :
ماهان سرور
آکوستیک ، فوم شانه تخم مرغی ، پنل صداگیر ، یونولیت
دستگاه جوجه کشی حرفه ای
فروش آنلاین لباس کودک
خرید فالوور ایرانی
خرید فالوور اینستاگرام
خرید ممبر تلگرام

[ + افزودن آگهی متنی جدید ]




نمايش نتايج 1 به 5 از 5

نام تاپيک: حذف گره در لیست پیوندی

  1. #1
    داره خودمونی میشه
    تاريخ عضويت
    Apr 2010
    پست ها
    21

    پيش فرض حذف گره در لیست پیوندی

    سلام دوستان.ببخشید توی کتاب schutlz درس ساختمان داده برای حذف یک گره با اطلاعات معلوم ITEM الگوریتم زیر رو داده و من میخوام به کد c++ تبدیلش کنم. هرجا تو اینترنت سر زذم با استفاده از کلاس node اینکارو انجام دادن، پس یعنی با تبدیل این الگوریتم به c++ عملیات حذف رو انجام داد بدون نوشتن کلاس nodeو اینا؟ میشه کسی این کد رو برام به c++ تبدیل کنه؟
    START مکان ابتدای لیست
    LINK آرایه مربوط به فیلد اشاره گر به گره بعدی
    INFO آرایه مربوط به اطلاعات فیلد
    LOC مکان گره n
    LOCP مکان گره قبل از n
    SAVE مکان گره قبلی
    if START=NULL then
    set LOC:=NULL and LOCP:=NULL , and return
    if INFO[START]=ITEM , then
    set LOC:=START and LOCP=NULL, and return
    set SAVE:=START and PTR:=LINK[START]
    while PTR!=NULL
    if INFO[PTR]=ITEM then
    set LOC:=PTR and LOCP:=SAVE, and return
    set SAVE:=PTR and PTR:=LINK[PTR]
    end while
    set LOC:=NULL
    return

  2. #2
    داره خودمونی میشه
    تاريخ عضويت
    Apr 2010
    پست ها
    21

    پيش فرض

    لااقل یکی بگه مگه میشه بدون استفاده از کلاسnode و کلاس linklist، تابعی برای یافتن گره مورد نظر در لیست پیوندی نوشت؟ آخه الگوریتم بالا در کتاب schultz با دو آرایه link و info و بدون کلاسه
    لطفا راهنماییم کنید

  3. #3
    داره خودمونی میشه
    تاريخ عضويت
    Apr 2010
    پست ها
    21

    پيش فرض

    یعنی اینقدر سوالم سخته که کسی حاضر نیست کمکم کنه؟ start رو در ورودی برنامه به ما میدن؟

  4. #4
    در آغاز فعالیت
    تاريخ عضويت
    Dec 2009
    پست ها
    13

    پيش فرض

    این یه برنامه کامل که شامل یک لیست رو ایجاد میکنه چاپش می کنه و گره مورد نظر رو حذف می کنه
    امیدوارم به دردت بخوره یه مثال از کتاب جعفرنژاد قمی
    #include "iostream.h"
    #include "stdlib.h"
    #include "conio.h"
    class node {
    friend class linkedList;
    private:
    char name[30] ;
    int stno ;
    int unit ;
    node *next;
    };
    class linkedList {
    public:
    linkedList();
    ~linkedList();
    void enter ();
    void display ();
    void delNode ();
    private:
    node *first;
    node *last;
    };
    //***************
    linkedList::linkedList()
    {
    first = last = NULL;
    }
    //***************
    linkedList::~linkedList()
    {
    node *curPtr = first;
    node *temp;
    while(curPtr)
    {
    temp = curPtr;
    delete temp;
    curPtr = curPtr -> next;
    }
    }
    //***************
    void linkedList::enter()
    {
    node *help;
    help = new node;
    help -> next = NULL ;
    if (first == NULL)
    first = last = help ;
    else
    {
    last -> next = help;
    last = help;
    }
    cout << "Enter name of student:";
    cin.getline(last -> name, 30) ;
    cout << "Enter student number :";
    cin >> last -> stno;
    cout << "Enter number of unit :";
    cin >> last -> unit;
    }
    //********************
    void linkedList::display()
    {
    node *h;
    int i ;
    if (first == NULL) {
    cout << "List is empty .";
    getch() ;
    return;
    }
    h = first ;
    clrscr() ;
    gotoxy(5,4) ;
    cout << "name st.number unit ";
    gotoxy(5, 5);
    cout <<"--------- --------- -----" ;
    i = 6 ;
    do {
    gotoxy(1, i);
    cout << h -> name;
    gotoxy(25, i);
    cout << h -> stno;
    gotoxy(38, i);
    cout << h -> unit;
    i ++ ;
    h = h -> next ;
    } while (h != NULL) ;
    gotoxy(5, i++) ;
    cout << "**********************" ;
    cout << "***************" ;
    gotoxy(10, i++) ;
    cout << "Press a key to continue.";
    getch() ;
    }
    //*****************
    void linkedList::delNode()
    {
    node *h, *p;
    int stnum ;
    if(!first)
    {
    cout << "List is empty.";
    getch();
    return;
    }
    cout << "Enter student number for delete:";
    cin >> stnum ;
    h = p = first ;
    while (h != NULL)
    {
    if (h -> stno != stnum)
    {
    p = h ;
    h = h -> next ;
    continue ;
    }
    else { //remove from start
    if (h == first) {
    first = h -> next ;
    delete h ;
    delete p ;
    break ;
    }//end of if
    else {
    if(h == last)
    last = p;
    p -> next = h -> next;
    delete h ;
    break ;
    }//end of else
    }//end of else
    }//end of while
    }
    //****************
    int menu();
    //****************
    int main ()
    {
    linkedList list;
    while (1)
    {
    clrscr() ;
    switch (menu())
    {
    case 1:
    list.enter() ;
    break ;
    case 2:
    list.delNode() ;
    break ;
    case 3:
    list.display() ;
    break ;
    case 4:
    exit(0) ;
    }//end of switch
    } //end of while
    } // end of main
    //********************
    int menu()
    {
    char c[5];
    cout << "1.Enter name to list\n";
    cout << "2.Remove name from list\n";
    cout << "3.Print the list\n";
    cout << "4.Exit from program\n";
    cout << "Enter your select(1-4):";
    cin.getline(c, 5);
    return atoi(c);
    }

  5. #5
    در آغاز فعالیت
    تاريخ عضويت
    Dec 2009
    پست ها
    13

    پيش فرض

    این یه برنامه کامل لیست پیوندی
    که با کلاس نوشته شده امیدوارم به دردت بخوره
    #include "iostream.h"
    #include "stdlib.h"
    #include "conio.h"
    class node {
    friend class linkedList;
    private:
    char name[30] ;
    int stno ;
    int unit ;
    node *next;
    };
    class linkedList {
    public:
    linkedList();
    ~linkedList();
    void enter ();
    void display ();
    void delNode ();
    private:
    node *first;
    node *last;
    };
    //***************
    linkedList::linkedList()
    {
    first = last = NULL;
    }
    //***************
    linkedList::~linkedList()
    {
    node *curPtr = first;
    node *temp;
    while(curPtr)
    {
    temp = curPtr;
    delete temp;
    curPtr = curPtr -> next;
    }
    }
    //***************
    void linkedList::enter()
    {
    node *help;
    help = new node;
    help -> next = NULL ;
    if (first == NULL)
    first = last = help ;
    else
    {
    last -> next = help;
    last = help;
    }
    cout << "Enter name of student:";
    cin.getline(last -> name, 30) ;
    cout << "Enter student number :";
    cin >> last -> stno;
    cout << "Enter number of unit :";
    cin >> last -> unit;
    }
    //********************
    void linkedList::display()
    {
    node *h;
    int i ;
    if (first == NULL) {
    cout << "List is empty .";
    getch() ;
    return;
    }
    h = first ;
    clrscr() ;
    gotoxy(5,4) ;
    cout << "name st.number unit ";
    gotoxy(5, 5);
    cout <<"--------- --------- -----" ;
    i = 6 ;
    do {
    gotoxy(1, i);
    cout << h -> name;
    gotoxy(25, i);
    cout << h -> stno;
    gotoxy(38, i);
    cout << h -> unit;
    i ++ ;
    h = h -> next ;
    } while (h != NULL) ;
    gotoxy(5, i++) ;
    cout << "**********************" ;
    cout << "***************" ;
    gotoxy(10, i++) ;
    cout << "Press a key to continue.";
    getch() ;
    }
    //*****************
    void linkedList::delNode()
    {
    node *h, *p;
    int stnum ;
    if(!first)
    {
    cout << "List is empty.";
    getch();
    return;
    }
    cout << "Enter student number for delete:";
    cin >> stnum ;
    h = p = first ;
    while (h != NULL)
    {
    if (h -> stno != stnum)
    {
    p = h ;
    h = h -> next ;
    continue ;
    }
    else { //remove from start
    if (h == first) {
    first = h -> next ;
    delete h ;
    delete p ;
    break ;
    }//end of if
    else {
    if(h == last)
    last = p;
    p -> next = h -> next;
    delete h ;
    break ;
    }//end of else
    }//end of else
    }//end of while
    }
    //****************
    int menu();
    //****************
    int main ()
    {
    linkedList list;
    while (1)
    {
    clrscr() ;
    switch (menu())
    {
    case 1:
    list.enter() ;
    break ;
    case 2:
    list.delNode() ;
    break ;
    case 3:
    list.display() ;
    break ;
    case 4:
    exit(0) ;
    }//end of switch
    } //end of while
    } // end of main
    //********************
    int menu()
    {
    char c[5];
    cout << "1.Enter name to list\n";
    cout << "2.Remove name from list\n";
    cout << "3.Print the list\n";
    cout << "4.Exit from program\n";
    cout << "Enter your select(1-4):";
    cin.getline(c, 5);
    return atoi(c);
    }

Thread Information

Users Browsing this Thread

هم اکنون 1 کاربر در حال مشاهده این تاپیک میباشد. (0 کاربر عضو شده و 1 مهمان)

User Tag List

قوانين ايجاد تاپيک در انجمن

  • شما نمی توانید تاپیک ایحاد کنید
  • شما نمی توانید پاسخی ارسال کنید
  • شما نمی توانید فایل پیوست کنید
  • شما نمی توانید پاسخ خود را ویرایش کنید
  •