• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            隨筆 - 18  文章 - 5  trackbacks - 0
            <2025年8月>
            272829303112
            3456789
            10111213141516
            17181920212223
            24252627282930
            31123456

            常用鏈接

            留言簿

            隨筆分類

            隨筆檔案

            文章分類

            文章檔案

            程序設(shè)計(jì)基礎(chǔ)

            牛們

            搜索

            •  

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            1. An exercise on lisk
            • Write a definition of LIST_ENTRY, and the insertion and deletion operations
            • Write a simple line editor
            Keep the entire text on a linked list, one line in a separate node. Start the program with entering LINEEDIT file, after which a prompt appears along with the line number. If the letter “I” is entered with a number n following it, then insert the text to be followed before line n. If “I” is not followed by a number, then insert the text before the current line. If “D” is entered with two numbers n and m, one n, or no number following it, then delete lines n through m, line n, or the current line. Do the same with the command, “L”, which stands for listing lines. If “A” is entered, then append the text to the existing lines. Entry “E” signifies exit and saving the text in a file.
            //這道題實(shí)在做不出,參考了別的同學(xué)的…… 
            #include<iostream>
            #include
            <fstream>
            using namespace std;
            ifstream fin(
            "test.txt");
            int cl=0;
            //建立LIST_ENTRY類 
            class LIST_ENTRY
            {
                
            public:
                    
            struct node
                    {
                        
            public:
                            node 
            *next;
                            
            string s0;
                            node(
            string s="")
                            {
                                s0
            =s;
                                next
            =NULL;
                            }
                    }
            *first;
                    
            int l;
                    LIST_ENTRY()
                    {
                        l
            =0;
                        first
            =NULL;
                    }
            //A命令 
                    int ins(string x,int y=cl+1)
                    {
                        
            int t=y-2;
                        node 
            *p=first,*temp=new node(x);
                        
            if (t==-1)
                        {
                            temp
            ->next=first;
                            first
            =temp;
                            l
            ++;
                            cl
            ++;
                            
            return 1;
                        }
                        
            if (p==NULL)
                        
            return 0;
                        
            while(t)
                        {
                            t
            --;
                            p
            =p->next;
                            
            if(p==NULL)
                            
            return 0;
                        }
                        temp
            ->next=p->next;
                        p
            ->next=temp;
                        
            if(y==cl+1)
                        cl
            ++;
                        
            else 
                        cl
            =y+1;
                        l
            ++;
                        
            return 1;
                    }
            //D命令 
                    int del(int x)
                    {
                        node 
            *p=first;
                        
            if (x==1)
                        {
                            
            if (first==NULL)return 0;
                            first
            =first->next;
                            l
            --;
                            delete p;
                            
            return 1;
                        }
                        
            if(p==NULL)
                        
            return 0;
                        
            while (x-2)
                        {
                            x
            --;
                            p
            =p->next;
                            
            if(p==NULL)
                            
            return 0;
                        }
                        node 
            *temp=p->next;
                        
            if (temp!=NULL)
                        {
                            p
            ->next=temp->next;
                            delete temp;
                            l
            --;
                            
            return 1;
                        }
                        
            return 0;
                    }
            //E命令 
                    int lis(int x,int y=0,node* p=NULL)
                    {
                        
            if (x==1)
                        p
            =first;
                        
            if (y==1&&x==1)
                        freopen(
            "out.txt","w",stdout);
                        
            if (p==NULL)
                        
            return 0;
                        cl
            =x;
                        
            if (!y)
                        cout
            <<cl<<'>';
                        cout
            <<p->s0<<endl;
                        
            return lis(x+1,y,p->next);
                    }
            }a;
            int chg(char* c,string &s,int &x,int &y,string &s2)
            {
                
            int i,j;
                s
            ="",s2="";
                x
            =y=cl;
                
            if (c[1]!=' '||(c[0]!='I'&&c[0]!='D'&&c[0]!='A'))
                {
                    
            for(i=0;c[i];i++)
                    s
            +=c[i];
                    
            return 0;
                }
                s
            +=c[0];
                
            if (c[0]=='A')
                {
                    
            for (i=2,j=0;c[i];i++)
                    {
                        
            if(c[i]!=' ')j=1;
                        
            if(j==1)s2+=c[i];
                    }
                    
            return 0;
                }
                
            for (i=2;c[i];i++)
                    
            if (c[i]!=' ')
                    {
                        
            for (j=0;c[i]!=' '&&c[i];i++)
                            j
            =j*10+c[i]-'0';
                        y
            =x=j;
                        
            break;
                    }
                
            if (c[0]!='D')
                
            return 0;
                
            for (;c[i];i++)
                    
            if (c[i]!=' ')
                    {
                        
            for (j=0;c[i]!=' '&&c[i];i++)
                        j
            =j*10+c[i]-'0';
                        y
            =j;
                        
            break;
                    }
                
            return 0;
            }
            int main()
            {
                
            string s,s2;
                
            int x,y,i=0,j=0,k=0;
                
            char c[1000];
                
            while(fin.getline(c,1000,10))
                {
                    
            for(i=0,s="";c[i];i++)
                        s
            +=c[i];
                    a.ins(s);
                }
                cout
            <<"LINEEDIT.txt"<<endl;
                a.lis(
            1);
                cout
            <<cl<<'>';
                
            while(cin.getline(c,1000,10))
                {
                    chg(c,s,i,j,s2);
                    
            if(s=="L")
                    {
                        k
            =0;
                        a.lis(
            1);
                        cout
            <<cl<<'>';
                        
            continue;
                    }
                    
            if(s=="A")
                    {
                        a.ins(s2);
                        cout
            <<cl<<'>';
                        
            continue;
                    }
                    
            if(s=="I")
                    {
                        k
            =2;
                        cl
            =i;
                        cout
            <<cl<<'>';
                        
            continue;
                    }
                    
            if(s=="E")
                    {
                        k
            =0;
                        a.lis(
            1,1);
                        
            return 0;
                    }
                    
            if(s=="D")
                    {
                        
            for(k=j;k>=i;k--)
                            a.del(k);
                        k
            =0;
                        cl
            =a.l;
                        cout
            <<cl<<'>';
                        
            continue;
                    }
                    
            if(k==2)
                        a.ins(s,cl);
                    cout
            <<cl<<'>';
                }
                system(
            "pause");
                
            return 0;
            }
            2. An exercise on queue
            • Write a queue using a doubly linked list
            • Simulate a command-dispatching system
            – It can accept user?s commands (from „a? – „j?)
            – These commands will take 1~10s, respectively
            – The user commands will be enqueued if the program can not finish the previous commands
            – The program will quit if user inputs command „q?
            • Hints:
            – Use “_kbhit()” to determine whether user inputs a command
            – Use “Sleep(1000)” to simulate the 1-second processing
            • Add #include “Windows
            posted on 2010-11-01 08:28 jyy 閱讀(145) 評(píng)論(0)  編輯 收藏 引用 所屬分類: OJ平臺(tái)
            久久人人爽人人爽人人片AV麻豆| 国产精品熟女福利久久AV| 久久精品无码专区免费东京热| AV狠狠色丁香婷婷综合久久| 精品久久久久中文字| 99久久精品国产一区二区 | 久久久久99这里有精品10 | 精品国产乱码久久久久久浪潮 | 天天久久狠狠色综合| 久久久黄色大片| 中文字幕久久欲求不满| 精产国品久久一二三产区区别| 国产精品久久久久久久久久免费| 浪潮AV色综合久久天堂| 狠狠精品干练久久久无码中文字幕 | 久久精品国产91久久综合麻豆自制| 一本大道久久香蕉成人网| WWW婷婷AV久久久影片| 99久久99久久精品国产片果冻| 久久精品成人影院| 99久久亚洲综合精品成人| 亚洲欧美日韩精品久久亚洲区| 国内精品久久久久影院免费| 精品国产乱码久久久久久1区2区 | 国产成人久久精品麻豆一区| 久久精品国产亚洲精品2020| 久久精品中文无码资源站| 中文字幕精品久久久久人妻| 久久久久亚洲精品男人的天堂| 狠狠久久亚洲欧美专区| 久久国产高潮流白浆免费观看| 久久久久亚洲AV无码永不| 7777久久久国产精品消防器材| 久久这里只有精品首页| 久久无码AV一区二区三区| 欧美日韩久久中文字幕| 久久国产精品无| 中文字幕久久久久人妻| 亚洲国产精品无码久久久秋霞2| 无码人妻久久一区二区三区 | 久久精品免费一区二区三区|