标签: while-loop

从排序链接列表中删除重复项

我用 C++ 编写了以下代码,它从排序的链接列表中删除重复项。

#include <iostream>
using namespace std;

class Node
{
    public:
    int data;
    Node *next;
    
    Node(int data)
    {
        this->data = data;
        this->next = NULL;
    }
};


void push(Node* &head, Node* &tail, int data)
{
    if(head==NULL)
    {
        Node* newNode = new Node(data);
        head = newNode;
        tail = newNode;
        return;
    }
    
    else
    {
        Node* newNode = new Node(data);
        tail -> next = newNode;
        tail = newNode;
    }
}

void print(Node* &head)
{
    Node *temp = head;
    while(temp!=NULL)
    {
        cout<<temp->data<<" ";
        temp …
Run Code Online (Sandbox Code Playgroud)

c++ linked-list while-loop data-structures

1
推荐指数
1
解决办法
134
查看次数

等待字符串变得平等的正确方法

在Swing应用程序中,只有在用户输入正确答案后,才能继续使用该方法.正确的答案存储在一个字符串中,用户答案由另一个字符串的监听器设置.所以,代码是

while (!correctAnswer.equals(currentAnswer)) {
     // wait for user to click the button with the correct answer typed into the textfield
}
// and then continue
Run Code Online (Sandbox Code Playgroud)

这种方法一切都很好还是你会以某种方式重构它?它不会对CPU造成额外的惩罚吗?这是一个有点类似的问题.

java cpu-cycles while-loop

0
推荐指数
2
解决办法
1112
查看次数

可以在循环中使用while循环吗?

我要做的是以下内容:我有一个值数组,这些值最终将用于生成随机唯一字符串,但稍晚一点.首先,我想循环遍历数组中的所有值(foreach循环),然后我想限制它(while循环)这是一个正确的方法吗?

下面的代码不起作用,任何人都可以看到我做错了什么?

<?php 

    $array = array(
          '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', 
          'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 
          'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 
          'u', 'v', 'w', 'x', 'y', 'z', '!', '£', '$', '%',
          '^', '&', '*', '(', ')', '_', '+', '{', '}'
    );

    $length_of_unique_key = 15;
    $counter = 0;

    foreach($array as $values)
    {
          $counter++;

          while ($counter <= $length_of_unique_key)
          {

          }
    }

?>
Run Code Online (Sandbox Code Playgroud)

php while-loop

0
推荐指数
2
解决办法
2853
查看次数

Java while循环不循环

我的摇摆界面中有以下按钮

    private void solveButtonMouseClicked(java.awt.event.MouseEvent evt) {                                         


    step1(); 


}   
Run Code Online (Sandbox Code Playgroud)

它调用step1();

   private void step1(){

//step 1 solving the white cross around the yellow middle
        while( (!(F2.getBackground().equals(white))) & (!(F4.getBackground().equals(white))) & (!(F6.getBackground().equals(white))) & (!(F8.getBackground().equals(white)))){


         textArea.append("cnt");

        //top three pieces solved
        if(F2.getBackground().equals(white) && F4.getBackground().equals(white) && F6.getBackground().equals(white)){
            //solve F8 
            while(!(F8.getBackground().equals(white))){

                //check right side
                if(R2.getBackground().equals(white)){right(); right(); downinv(); rightinv(); rightinv();}
                else if(R4.getBackground().equals(white)){rightinv(); downinv(); right();}
                else if(R6.getBackground().equals(white)){right(); downinv(); rightinv();}
                else if(R8.getBackground().equals(white)){downinv();}
                //check left side
                else if(L2.getBackground().equals(white)){left(); left(); down(); leftinv(); leftinv();}
                else if(L4.getBackground().equals(white)){leftinv(); down(); left();}
                else if(L6.getBackground().equals(white)){left(); down(); leftinv();}
                else if(L8.getBackground().equals(white)){down();} …
Run Code Online (Sandbox Code Playgroud)

java while-loop

0
推荐指数
1
解决办法
2419
查看次数

PHP圆数,加十进制数

我正在使用一个简单的循环来回显一些数字

<?php
$inc = 0.25;
$start =  0.25;
$stop = 5.00;
?>

<?php while($start != ($stop + $inc)){ ?>
<option><?php echo $start ?></option>
<?php $start = $start + $inc; ?>
<?php } ?>
Run Code Online (Sandbox Code Playgroud)

但是5.00显示为5,4.50显示为4.5

我如何让这个脚本显示5.00,4.00,3.00,3.50

也为标题辩护,我不知道如何解释这个!

谢谢

php formatting loops decimal while-loop

0
推荐指数
1
解决办法
2772
查看次数

在C中循环帮助

我是C编程的新手,我来自Java背景.我想知道为什么在下面的代码中,在while循环中我必须输入十次输入,然后显示所有十个输入.我想尝试输入一次并立即显示.然后继续输入我的其他输入.

#include <stdio.h>
#include <stdlib.h>
#include "Helper.h"


main(){

print(PROGRAM_INFO); //prints program name and author
print(PROMPT);

char input [100]; //array to hold input from user
int isActive = 1; //1 continue shell, 0 terminate shell
int count = 0;

while (isActive == 1 && count < 10){
    print(PROMPT);
    ++count;
    scanf("%s", input);
    print(input);


}


}
Run Code Online (Sandbox Code Playgroud)

c printing scanf while-loop

0
推荐指数
1
解决办法
746
查看次数

为什么这个while循环不起作用?

好的,所以我正在尝试使用while循环创建一个程序来查找两个数字的最大公约数.这就是我提出的.但是,据我所知,程序似乎只是在我运行时完全跳过循环.(操作数保持为0,除数总是等于num1).谁在那里可以帮助新手?

/* Define variables for divisors and number of operations */

int num1, num2, divisor, opers;
opers = 0;

/* Prompt user for integers and accept input */

cout << "Please enter two integers with the smaller number first, separated by a space. ";
cout << endl;
cin >> num1 >> num2;

/* Make divisor the smaller of the two numbers */

divisor = num1;

/* While loop to calculate greatest common divisor and number of calculations */

while ( …
Run Code Online (Sandbox Code Playgroud)

c c++ while-loop

0
推荐指数
1
解决办法
786
查看次数

python:如何在这个简单的while循环中避免"列表索引超出范围"

我的L1数组包含像0.029999999999999999这样的数字,我想打印为0.03

我的代码有效,但最后会出错,因为最后一次计数超出了范围.我明白为什么它会破裂,但不知道如何解决它.谢谢

count = 1

while L1:
    print "%.2f" %L1[count]
    count = count + 1
Run Code Online (Sandbox Code Playgroud)

python loops while-loop

0
推荐指数
1
解决办法
4243
查看次数

执行while循环的最小次数是?

while循环执行的最小次数是多少?

它是零吗?

不是在谈论DO

c while-loop

0
推荐指数
1
解决办法
2万
查看次数

如何修复这个C#循环和处理代码?

我有一个Lat/Lon坐标列表,我正在处理一段时间(真实)循环.在循环期间,我正在构建一个将被发送到远程服务进行处理的查询.远程服务只能接受12对Lat/Lon坐标,但我的列表可能包含数千个.我想要做的是构建查询,然后发送它以便每12个循环处理一次.

List<string[]> lList = FromDB();

int i = 0;
int intLastIndex - lList.Count;
string strQuery = String.Empty

while(true)
{
    strQuery = lList[i][0] + "|" + lList[i][1];

    if(((i % 11) == 0) && (i != 0))
    {
        SendToRemoteService(strQuery);
        strQuery = String.Empty;
    }

    if(i == intLastIndex)
    {
        break;
    }

    i++
}
Run Code Online (Sandbox Code Playgroud)

但是,这会生成一个数组超出范围的异常,并且不会处理所有记录.有谁能建议更好的方法?

标记

c# while-loop

0
推荐指数
1
解决办法
227
查看次数